View Full Version : FileStream
  
Farhad.B.S
یک شنبه 09 شهریور 1382, 15:07 عصر
سلام.
چطور میشه در VB.Net با استفاده از FileStream کی فایل رو خوند یا توش نوشت ؟
ممنون.
S.Azish
دوشنبه 10 شهریور 1382, 16:38 عصر
'Writing to a file
Imports System
Imports System.IO
Class Test
    Public Shared Sub Main()
        ' Create an instance of StreamWriter to write text to a file.
        Dim sw As StreamWriter = New StreamWriter("TestFile.txt")
        ' Add some text to the file.
        sw.Write("This is the ")
        sw.WriteLine("header for the file.")
        sw.WriteLine("-------------------")
        ' Arbitrary objects can also be written to the file.
        sw.Write("The date is: ")
        sw.WriteLine(DateTime.Now)
        sw.Close()
    End Sub
End Class
'Reading from a file
Imports System
Imports System.IO
Class Test
    Public Shared Sub Main()
        Try
            ' Create an instance of StreamReader to read from a file.
            Dim sr As StreamReader = New StreamReader("TestFile.txt")
            Dim line As String
            ' Read and display the lines from the file until the end 
            ' of the file is reached.
            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
    End Sub
End Class
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.