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.
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


0