Ciao a tutti,
ho creato questa funzione che salva un file di testo in bytes.
codice:
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (filepath != null || filepath != "")
{
SaveFileDialog dlgSave = new SaveFileDialog();
dlgSave.Filter = "Text files (*.bin)|*.bin";
if (dlgSave.ShowDialog() == DialogResult.OK)
{
using (StreamWriter BW = new StreamWriter(dlgSave.FileName))
{
for (int i = 0; i < panel1.Controls.Count; i++)
{
if (panel1.Controls[i].Name.StartsWith("line"))
{
byte[] bytes = Encoding.ASCII.GetBytes(panel1.Controls[i].Text);
for (int b = 0; b < bytes.GetUpperBound(0); b++)
{
BW.Write(bytes[b]);
}
}
}
}
}
}
}
Una volta salvato cerco di aprirlo in questa maniera...
codice:
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog dlgOpen = new OpenFileDialog();
if (dlgOpen.ShowDialog() == DialogResult.OK)
{
byte[] bytes = File.ReadAllBytes(dlgOpen.FileName);
string output = System.Text.Encoding.ASCII.GetString(bytes);
MessageBox.Show(output);
}
}
L'output che mi viene dato non sono altro che i bytes...e quindi non mi viene tradotta nessuna stringa dal byte letto...
Qualcuno sa come posso fare a convertire un array di bytes in una stringa?