파일 존재 여부 확인 후 텍스트 파일 저장 하기
교교
2014.01.08 08:57:33
*: Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fileR As String
Dim thefile As String
Dim results As String
Dim newfile As System.IO.FileStream
thefile = "c:\filetest.txt"
results = Dir$(thefile)
If results = "" Then
newfile = System.IO.File.Create("c:\filetest.txt")
MsgBox("파일이 생성 되었습니다")
Else
fileR = My.Computer.FileSystem.ReadAllText("c:\filetest.txt",
System.Text.Encoding.UTF8)
TextBox1.Text = fileR
End If
End Sub
Private Sub 불러오기ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 불러오기ToolStripMenuItem.Click
OpenFileDialog1.ShowDialog()
End Sub
Private Sub 종료ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 종료ToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub 저장ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 저장ToolStripMenuItem.Click
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("c:\filetest.txt", False)
file.WriteLine(TextBox1.Text)
file.Close()
MsgBox("저장되었습니다")
End Sub
End Class
지정된 텍스트파일 존재 여부 확인 후
파일 수정 저장하는 프로그램입니다