Un esempio minimale
codice:import java.io.*; public class SerializeArray { public static void main(String[] args) { // Vettore di interi da serializzare int[] vettore = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; FileOutputStream fos = null; ObjectOutputStream oos = null; try { // Apro lo stream di output su un file chiamato "serial_array.ser" fos = new FileOutputStream("serial_array.ser"); oos = new ObjectOutputStream( fos ); // Serializzo l'array sul file oos.writeObject( vettore ); oos.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (oos != null) { try { oos.close(); } catch (Exception e) { } } else { if (fos != null) { try { fos.close(); } catch (Exception e) { } } } } } }
Ciao.![]()



Rispondi quotando