文件操作
1.如何在项目文件的同一目录下建立一个文本件
2.如何把字符串写到文本文件去
3.如何读取文本文件里的字符串
问题点数:20、回复次数:4Top
1 楼hdt(倦怠)回复于 2006-06-02 13:48:55 得分 3
ms-help://MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconwritingtexttofile.htmTop
2 楼copico(北北)回复于 2006-06-02 13:51:21 得分 6
dim ft as new io.filestream("123.txt",openorcreate)
dim dw as new io.streamwrite(ft)
dw.writeline("这是第一行")
dw.writeline("这是第二行")
dw.close()
ft.close()
////////////////////
读
dim ft as new io.filestream("123.txt",openorcreate)
dim dr as new io.streamread(ft)
msgbox dr.readline() '读第一行
msgbox dr.readline() '读第二行
dr.close()
ft.close()Top
3 楼why2002plus()回复于 2006-06-02 13:56:45 得分 7
1、System.IO.File.Create(Application.StartupPath + "e.txt")
2、写文件
Dim sw As StreamWriter = New StreamWriter(Application.StartupPath + "e.txt")
sw.Write("This is the ")
sw.WriteLine("header for the file.")
sw.WriteLine("-------------------")
sw.Write("The date is: ")
sw.WriteLine(DateTime.Now)
sw.Close()
3、读文件
Dim sr As StreamReader = New StreamReader(Application.StartupPath + "e.txt")
Dim line As String
Do
line = sr.ReadLine()
Console.WriteLine(Line)
Loop Until line Is Nothing
sr.Close()
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
Top
4 楼bitpolar(独自看天)回复于 2006-06-02 14:29:51 得分 4
在MSDN里面输入个File 或者 FileInfo 就能解决Top




