Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Module Module1
- Sub Main()
- Try
- Dim s As System.IO.Stream = Nothing
- ' stream per file
- Dim f As New FileStream(".\test.txt", FileMode.Create)
- ' stream che usa la memoria come endpoint
- Dim m As New MemoryStream()
- ' stream di rete
- Dim n As Net.Sockets.NetworkStream = Nothing
- ' su tutti gli stream si può operare con buffer
- Dim bf As New BufferedStream(f)
- ' Per leggere o scrivere oggetti si usano TextReader e TextWriter
- Using r As TextReader = New StreamReader(m)
- ' tutti gli oggetti che implementano l'interfaccia di sistema
- ' IDisposable
- Using w As TextWriter = New StreamWriter(m)
- Dim line As String
- Do
- line = Console.ReadLine()
- 'Dim buffer() As Byte =
- ' System.Text.Encoding.ASCII.GetBytes(line)
- 'bf.Write(buffer, 0, buffer.Length)
- w.WriteLine(line)
- Loop Until line = "."
- 'w.Close() ' la istruzione USING evita la necessità di CHIUDERE l'oggetto
- w.Flush()
- m.Seek(0, SeekOrigin.Begin)
- Dim c As String = String.Empty
- Do
- c = r.ReadLine()
- If Not String.IsNullOrEmpty(c) Then Console.WriteLine(c)
- Loop Until String.IsNullOrEmpty(c)
- End Using
- End Using
- Catch ex As IOException
- Console.WriteLine("Problemi in lettura o scrittura su stream.")
- Catch ex As Exception
- Console.WriteLine("Altri errori")
- End Try
- Console.ReadLine()
- End Sub
- End Module
Add Comment
Please, Sign In to add comment