2016-08-05 2 views
1

streamWriter를 사용하는 방법을 읽었습니다. Preserving existing text when writing to file 그래도 코드가 실제로 동일하더라도 아무 것도 파일에 쓰여지지 않습니다. 여기에 코드입니다 :스트림 작성기로 파일에 행 쓰기

Private Sub Main() 
Dim todaysdate As String = DateTime.Today 
todaysdate = todaysdate.Replace("/", ".") 
Dim todayFile As String = "dated\" & todaysdate & ".txt." 
'this just creates the name and filepath that i want my file to be located at 

    If File.Exists(todayFile) = False Then 

      Dim Day As StreamWriter 

      Day = New StreamWriter(todayFile, True) 
      Day.WriteLine("sandwhich") 
    end if 
end sub 

그래서 그래,이 말 그대로 그냥 파일을 생성하지만 난 파일을 열 때 비어 (거기에 아무 문제를, 파일이 올바른 날짜와 위치에 관한 정보들로 구성되어)! 어떤 제안?

답변

0

봅니다이 코드

Dim file_ As System.IO.StreamWriter 
     file_ = My.Computer.FileSystem.OpenTextFileWriter(todayFile, True) 
     file_.WriteLine("sandwich") 
     file_.Close() 
를 사용하는