Hola a todos;
Tengo la siguiente duda :
Debo guardar en un archivo, un array de bytes llamado instrucciones[] y un texto guardado en un area de texto(swing).
Solo logro guardar y abrir el texto, con el siguiente codigo:
Abrir:
JFileChooser fileChooser = new JFileChooser();
int seleccion = fileChooser.showOpenDialog(areaTexto);
if (seleccion == JFileChooser.APPROVE_OPTION){
try {
File fichero = fileChooser.getSelectedFile();
BufferedReader reader;
reader = new BufferedReader(new FileReader(fichero));
String lineaTotal="";
String linea = reader.readLine();
while (linea != null)
{
lineaTotal = lineaTotal + linea + System.getProperty("line.separator");
linea = reader.readLine();
}
areaTexto.setText(lineaTotal);
reader.close();
} catch (IOException ex) {
Logger.getLogger(miVentana.class.getName()).log(Le vel.SEVERE, null, ex);
}
}
Guardar:
JFileChooser fileChooser = new JFileChooser();
int seleccion = fileChooser.showSaveDialog(areaTexto);
if (seleccion == JFileChooser.APPROVE_OPTION){
File fichero = fileChooser.getSelectedFile();
PrintWriter writer;
try {
writer = new PrintWriter(fichero);
writer.print(areaTexto.getText());
writer.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(miVentana.class.getName()).log(Le vel.SEVERE, null, ex);
}
}