Foros del Web » Programación para mayores de 30 ;) » Java »

Guardar y leer en un archivo, un array de bytes y un texto

Estas en el tema de Guardar y leer en un archivo, un array de bytes y un texto en el foro de Java en Foros del Web. Hola a todos; Tengo la siguiente duda : Debo guardar en un archivo, un array de bytes llamado instrucciones[] y un texto guardado en un ...
  #1 (permalink)  
Antiguo 02/10/2010, 05:22
 
Fecha de Ingreso: septiembre-2010
Mensajes: 9
Antigüedad: 13 años, 7 meses
Puntos: 0
Pregunta Guardar y leer en un archivo, un array de bytes y un texto

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);
}
}

Etiquetas: byte
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:05.