Java - ESCRITURA FITXERO

 
Vista:

ESCRITURA FITXERO

Publicado por JOMISMO (28 intervenciones) el 18/05/2005 11:37:13
Bien os paso esto que lo pille de un ejemplo de internet pasa que estaba con errores.
lo arregle pero ahora me da los errores que veis al final del codigo.
Bueno me pregunto no capturo la excepcion con el try ant cahtc que ele puse ??


import java.io.*;
import java.util.*;

public class EscrituraFitxer {


public EscrituraFitxer() {
}


public boolean Escritura(){



double[] precios={1350, 400, 890, 6200, 8730};
int[] unidades={5, 7, 12, 8, 30};
String[] descripciones={"paquetes de papel", "lápices", "bolígrafos", "carteras", "mesas"};

try{
DataOutputStream salida=new DataOutputStream(new FileOutputStream("pedido.txt"));
for (int i=0; i<precios.length; i ++) {

salida.writeChars(descripciones[i]);
salida.writeChar('\n');
salida.writeInt(unidades[i]);
salida.writeChar('\t');
salida.writeDouble(precios[i]);
}
salida.close();


}catch(java.io.FileNotFoundException ioex){


System.out.println("Error");}
return true;
}
}


EscrituraFitxer.java [22:1] unreported exception java.io.IOException; must be caught or declared to be thrown
salida.writeChars(descripciones[i]);
^
EscrituraFitxer.java [23:1] unreported exception java.io.IOException; must be caught or declared to be thrown
salida.writeChar('\n');
^
EscrituraFitxer.java [24:1] unreported exception java.io.IOException; must be caught or declared to be thrown
salida.writeInt(unidades[i]);
^
EscrituraFitxer.java [25:1] unreported exception java.io.IOException; must be caught or declared to be thrown
salida.writeChar('\t');
^
EscrituraFitxer.java [26:1] unreported exception java.io.IOException; must be caught or declared to be thrown
salida.writeDouble(precios[i]);
^
EscrituraFitxer.java [28:1] unreported exception java.io.IOException; must be caught or declared to be thrown
salida.close();
^
6 errors
Errors compiling EscrituraFitxer.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 755
Bronce
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

RE:ESCRITURA FITXERO

Publicado por Yamil Bracho (2315 intervenciones) el 18/05/2005 15:47:37
El mismo compilador te esta diceindo el problema. Debes capturar la excepcion que te esta reportando. Agrega a tu codigo lo siguiente:

salida.close();

}catch(java.io.FileNotFoundException ioex) {
System.out.println("Error");
} catch( IOException ioe ) {
ioe.printStackTrace();
}
...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar