2009-08-26 4 views

답변

12
Dim FILE_NAME As String = "C:\textfile.txt" 
Dim i As Integer 
Dim aryText(4) As String 

aryText(0) = "Mary WriteLine" 
aryText(1) = "Had" 
aryText(2) = "Another" 
aryText(3) = "Little" 
aryText(4) = "One" 

Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True) 

For i = 0 To 4 
    objWriter.WriteLine(aryText(i)) 
Next 

objWriter.Close() 
MsgBox("Text Appended to the File") 

당신이 System.IO.StreamWriter의 생성자가 이미있는 경우 파일에 추가하거나, 그렇지 않은 경우 새로 만듭니다에서 True에 두 번째 매개 변수를 설정하면

Procedure logfile() 
{ 
    if "C:\textfile.txt"=exist then 
     open the textfile; 
    else 
     create the textfile; 
    end if 
    go to the end of the textfile; 
    write new line in the textfile; 
    save; 
    close; 
} 
.

2

이 유형의 로그 아웃을 수행하는 구성 요소를 사용하는 것이 가장 좋습니다. Logging Application Block은 예를 들어 Enterprise Library입니다. 그렇게하면 유연성, 확장 성을 얻게되며 로그 파일과 관련이 없습니다. ...

는 (죄송합니다, 제가 VB 모르지만, 번역 충분히 단순해야한다) 특별히 귀하의 질문에 대답하려면

void Main() 
{ 
    using(var fs = File.Open(@"c:\textfile.txt", FileMode.Append)) 
    { 
     using(var sw = new StreamWriter(fs)) 
     { 
      sw.WriteLine("New Line"); 
      sw.Close(); 
     } 

     fs.Close(); 
    } 
} 
8

이 너무 한 줄에 달성 될 수있다 :

System.IO.File.AppendAllText(filePath, "Hello World" & vbCrLf) 

누락 된 파일을 생성하고 텍스트를 추가 한 다음 다시 닫습니다.

MSDN, File.AppendAllText Method을 참조하십시오.

+0

매우 간단하고 깨끗합니다. –