Rex Romae (Normal User)
Newbie
Messaggi: 9
Iscritto: 30/12/2007
|
Questo topic è stato chiuso dal moderatore 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??
Codice sorgente - presumibilmente C# / VB.NET |
// Select the file
OpenFileDialog file = new OpenFileDialog();
file.Title = "Select a file";
file.Filter = "All Files (*.*)|*.*";
file.ShowDialog();
textBox1.Text = file.FileName;
|
|
|
crash outside control (Normal User)
Expert
Messaggi: 217
Iscritto: 12/02/2008
|
Prova con questo:
Codice sorgente - presumibilmente VB.NET |
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
|
|
Rex Romae (Normal User)
Newbie
Messaggi: 9
Iscritto: 30/12/2007
|
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?
Codice sorgente - presumibilmente Delphi |
// 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
|
|
Il Totem (Admin)
Guru^2
Messaggi: 3635
Iscritto: 24/01/2006
|
Codice sorgente - presumibilmente Delphi |
// 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 il 22/06/2008 alle 9:29 |
|
Rex Romae (Normal User)
Newbie
Messaggi: 9
Iscritto: 30/12/2007
|
grazie ho risolto!
|
|