1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
package assurence;
import java.awt.Label;
import java.util.*;
import java.util.ArrayList;
import java.io.*;
/**
*
* @author Anas
*/
public class NewClass {
public static void main(String [] args){
ArrayList B=new ArrayList();
int n=0;
B.add(1);
B.add(2);
B.add(3);
B.add(4);
/*
try{
FileOutputStream sortie1 = new FileOutputStream("c:\\test2.dat");
ObjectOutputStream s1 = new ObjectOutputStream(sortie1);
//s1.writeObject(B);
s1.writeObject(B);
s1.flush();
s1.close();
}
catch(IOException io) {io.printStackTrace();}
*/
try{
FileInputStream entre2 = new FileInputStream("c:\\test2.dat");
ObjectInputStream e2 = new ObjectInputStream(entre2);
B.addAll((ArrayList)(e2.readObject()));
e2.close();
}
catch(IOException io) {io.printStackTrace();}
catch(ClassNotFoundException c){c.printStackTrace();}
//System.out.println(n);
//Integer.valueOf((B.get(1)).toString())=+2;
n=Integer.valueOf((B.get(1)).toString())+2;
//B.set(1, n);
//n+=2;
//System.out.println(n);
B.set(1,n);
System.out.println(B.get(1));
try{
FileOutputStream sortie1 = new FileOutputStream("c:\\test2.dat");
ObjectOutputStream s1 = new ObjectOutputStream(sortie1);
s1.writeObject(B);
// s1.writeObject(n);
s1.flush();
s1.close();
}
catch(IOException io) {io.printStackTrace();}
}
} |
Partager