ASCII(Plain Text) vs. Binary Files

ASCII File
ASCII = American Standard Code for Information Interchange
글자의 내용만 있고, 형식을 저장하지 않는다(plain text).
메모장과 같은 Text Editor로 보기와 편집이 가능하다.
호환용 형식(interchange format)으로 많이 사용된다.
파일의 크기가 커질 수 있다.
Character Set의 문제(encoding-decoding)가 발생할 수 있다.(Unicode, EUC-KR 등)
관련 확장자 : TXT, XML, DXF, CSV, PS
관련사이트 : Power of Plain Text

Binary Files
자료를 0과 1의 형태(이진 즉 binary)로 저장한다.
소프트웨어 제작사의 노하우가 숨어져 있다. 일반적으로 그 구조가 어떻게 되어 있는지 알 수 없다. 따라서 특정 편집기를 통해서 열기와 편집이 가능하다.
문서 파일의 경우, 글자의 내용뿐만 아니라 형식(글자체, 모양 등)도 저장한다(formatted text, styled text or rich text).
관련 확장자 : HWP, DOC, DWG, XLS, PDF

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by 솔라뷰

2008/09/10 14:16 2008/09/10 14:16
, ,
Response
No Trackback , No Comment
RSS :
http://www.solarview.net/rss/response/195

파일경로와 파일이름

1. 프로그램이 시작된 경로를 알아내기
- App.Path 함수를 사용한다.

2. App.Path 사용시 주의할 점
- 루트 디렉토리일 경우 "\"를 함께 반환한다.
- 루트 디렉토리가 아닐 경우, 끝에 "\"가 없다.

3. 더 좋은 App.Path (출처 : http://www.freevbcode.com/ShowCode.asp?ID=878)
항상 끝에 "\"가 붙게 한다.

Public Function AppPath() As String
Dim NewPath As String
NewPath = App.Path
If Right(App.Path, 1) <> "\" Then NewPath = NewPath & "\"
AppPath = NewPath
End Function

사용예
    'Open "C:\IA Program\입력값\FormData_5장.txt" For Input As #1
Open AppPath & "입력값\FormData_5장.txt" For Input As #1


4. 프로그램 시작 경로에서 파일명 가져오기
Function GetFileName(sFileName As String) As String
Dim FullFilename As String
'
'파일이름
If Right$(Trim$(App.Path), 1) = "\" Then
FullFilename = App.Path + sFileName
Else
FullFilename = App.Path + "\" + sFileName
End If
'
GetFileName = FullFilename
'
End Function

사용예 : FormData_5장.txt를 프로그램시작경로에서 찾는다.
myFile = GetFileName("FormData_5장.txt")


5. 전체파일명에서 경로만 뽑아내기
Function GetPath(strFullFilename As String) As String
'
Dim strPath As String
strPath = Mid(strFullFilename, 1, InStrRev(strFullFilename, "\", , vbTextCompare) - 1)
If Len(strPath) = 0 Then
strPath = App.Path
End If
GetPath = strPath
'
End Function


호환성 : Visual Basic 5, 6

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by 솔라뷰

2008/08/28 14:48 2008/08/28 14:48
, ,
Response
No Trackback , No Comment
RSS :
http://www.solarview.net/rss/response/194

DXF를 읽어오는 모듈을 정리

과거 동적배열로 된 변수들을 Generic.List와 Generic.Dictionary로 변경하였다. 파일 읽는 시간이 놀랍게 줄었다.
리스트와 딕셔너리도 마치 동적배열처럼 사용할 수 있다.

'옛날 코드
Dim DXFEntities() As SV_DXFEntity
ReDim Preserve DXFEntities(k)
DXFEntities(k) = New SV_DXFEntity


'개체 클래스
Public Class SV_DXFEntity
Private m_Type As String '자료명
Private m_CodeValue As Generic.Dictionary(Of Integer, String)
'
Public Sub New()
m_CodeValue = New Generic.Dictionary(Of Integer, String)
End Sub
Default Public Property CodeValue(ByVal groupCode As Integer) As String
Get
Return m_CodeValue(groupCode)
End Get
Set(ByVal value As String)
m_CodeValue(groupCode) = value
End Set
End Property
Public Property Type() As String
Get
Return m_Type
End Get
Set(ByVal value As String)
m_Type = value
End Set
End Property
Public Sub Add(ByVal myCode As Integer, ByVal myValue As String)
If m_CodeValue.ContainsKey(myCode) Then Exit Sub
m_CodeValue.Add(myCode, myValue)
End Sub

End Class


'엔티티를 원소로하는 리스트 선언
Dim DXFEntities As Generic.List(Of SV_DXFEntity)

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by 솔라뷰

2008/02/23 04:25 2008/02/23 04:25
, , , ,
Response
No Trackback , No Comment
RSS :
http://www.solarview.net/rss/response/190

한글 텍스트 파일 읽기

한글 텍스트 파일을 읽기 위해서는 인코딩을 다음과 같이 지정해 주어야 한다.

'파일스트림 열기
Dim fs As New FileStream("myhangultext.txt", FileMode.Open, FileAccess.Read)
'
'스트림리더 열기
'*** 주의 : System.Text.Encoding.Default를 지정해야 '한글'을 읽어올 수 있음!!!
'시스템의 현재 ANSI 코드 페이지에 대한 인코딩을 가져옵니다
'Dim Reader As New StreamReader(fs, System.Text.Encoding.Default)
'--> 사실 이렇게 하면, 한글윈도우이어야 읽을 수 있다.
'명확히 한글을 읽을 수 있게 하려면 다음과 같이 해야 한다.
Dim Reader As New StreamReader(fs, System.Text.Encoding.GetEncoding(949))
'여기서 949는 한글에 대한 code page이다.
'
'자료를 읽기
Call Parse(Reader)
'
'스트림리더 닫기
Reader.Close()

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by 솔라뷰

2006/10/18 22:42 2006/10/18 22:42
, , , , ,
Response
No Trackback , No Comment
RSS :
http://www.solarview.net/rss/response/84

XML File Parsing in VB.NET

보호된 글 입니다. 비밀번호를 입력하세요.