Oppure

Loading
Questo topic e' stato chiuso dal moderatore.
21/06/08 14:49
Rex Romae
Ho cercato materiale su motori di ricerca ma non ho trovato quello che mi interessa. Devo aprire il file in modalità binaria e poi leggerlo come posso fare??

// Select the file
OpenFileDialog file = new OpenFileDialog();
file.Title = "Select a file";
file.Filter = "All Files (*.*)|*.*";
file.ShowDialog();
textBox1.Text = file.FileName;
aaa
21/06/08 16:05
crash outside control
Prova con questo:

Dim new_stream As Stream = File.Open("f:\a.bin", FileMode.Open, FileAccess.Read)
        Using bw As New BinaryReader(new_stream)
            Do Until bw.PeekChar() = -1
                txtleggi.Text &= bw.ReadByte
            Loop
        End Using


Poi ci fai sapere, ciao :)
aaa
21/06/08 18:50
Rex Romae
Scusa ho scordato di specificare che sto programmando in C# ora e il codice mi serviva per C#... cmq l'ho tradotto e ora ho sistemato un po le cose ma non riesco a capire dove sbaglio xke l'applicazione si impalla quando leggo un semplice file.
Potete aiutarmi?
            // Select the file
            OpenFileDialog file = new OpenFileDialog();
            file.Title = "Select a file";
            file.Filter = "All Files (*.*)|*.*";
            file.ShowDialog();
            textBox1.Text = file.FileName;

            // Open and Read the file
            Stream new_stream = File.Open(file.FileName, FileMode.Open, FileAccess.Read);
            BinaryReader bw = new BinaryReader(new_stream);
            while (bw.PeekChar() >= 0)
            {
                textBox2.Text = bw.ToString();
            }


grazie mille :k:
aaa
22/06/08 7:26
Il Totem
// Select the file
OpenFileDialog file = new OpenFileDialog();
file.Title = "Select a file";
file.Filter = "All Files (*.*)|*.*";
file.ShowDialog();
textBox1.Text = file.FileName;

// Open and Read the file
Stream new_stream = File.Open(file.FileName, FileMode.Open, FileAccess.Read);
BinaryReader bw = new BinaryReader(new_stream);
while (bw.PeekChar() >= 0)
{
   textBox2.Text += bw.ReadChar();
}
bw.Close();

bw.ToString ti restituisce la stringa "System.IO.BinaryReader" e non legge niente, quindi non avanza di posizione. In conclusione PeekChar restituisce sempre il valore del primo byte, e sempre maggiore di -1.
Ultima modifica effettuata da Il Totem 22/06/08 7:29
aaa
22/06/08 11:45
Rex Romae
grazie ho risolto!:k:
aaa