Este está muy bien AQUI AQUI AQUI
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
, espero leer mas cosillas asi.
Cita de: BlackM4ster en 5 Marzo 2015, 08:14 AM
Cual de los logos es el tuyo?
Cita de: dimitrix en 6 Marzo 2015, 17:34 PMCon lo maja que es Marina, no metas a tu ex en esto.
Trust me! Funciona!!!
Cita de: Reina_Negra en 5 Marzo 2015, 22:14 PM
Segundo, invéntate una excusa
java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2601)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1319)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at Principal.importarProductos(Principal.java:101)
at Principal.main(Principal.java:26)
private static void importarProductos(){
ArrayList<Producto> arrayAuxiliar = new ArrayList<Producto>();
ObjectInputStream ois = null;
Object aux = null;
try {
ois = new ObjectInputStream(new FileInputStream("./estanteria.obj"));
aux = ois.readObject();
while (aux!=null)
{
if (aux instanceof Producto)
System.out.println(aux);
aux = ois.readObject();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("es del fichero");
} catch (IOException e) {
e.printStackTrace();
System.out.println("es IO");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("de la clase si que no");
}finally{
try{
ois.close();
}catch(IOException f){}
}
}
private static void exportaProductos(ArrayList p){
ObjectOutputStream fichero = null;
try {
fichero = new ObjectOutputStream(new FileOutputStream("./estanteria.obj"));
for(int x = 0; x<p.size(); x++){
fichero.writeObject(p.get(x));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try{
fichero.close();
}catch(IOException f){}
}
}
Cita de: Gus Garsaky en 2 Marzo 2015, 20:44 PM
Lol xD. Suele pasar
PD: Puedes aprovechar el autocloseable:public void exportProducts(List<ProductVO> products) {
try(ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("D:\\products.obj"))) {
for(ProductVO product : products)
out.writeObject(product);
} catch(FileNotFoundException ex) {
ex.printStackTrace();
} catch(IOException ex2) {
ex2.printStackTrace();
}
}
Así ya no tienes que preocuparte por cerrar flujos o conexiones