Last active
August 29, 2015 14:17
-
-
Save xcv58/bd4bf088e9ef8d837dc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
public class Temp { | |
public enum TYPE { | |
INT, LONG, FLOAT, DOUBLE, STRING, DATE, DECIMAL, CHAR, VARCHAR | |
} | |
private List<TYPE> list; | |
Temp() { | |
list = new ArrayList<TYPE>(); | |
list.add(TYPE.INT); | |
list.add(TYPE.DOUBLE); | |
list.add(TYPE.DATE); | |
list.add(TYPE.INT); | |
list.add(TYPE.DATE); | |
} | |
public static void main(String args[]) { | |
Temp t = new Temp(); | |
for (TYPE type : t.list) { | |
System.out.println(type); | |
} | |
System.out.println("-----serialize List-----"); | |
String fileName = "temp"; | |
try { | |
FileOutputStream fos = new FileOutputStream(fileName); | |
ObjectOutputStream oos = new ObjectOutputStream(fos); | |
oos.writeObject(t.list); | |
fos.close(); | |
System.out.println("-----serialize finish-----"); | |
FileInputStream fis = new FileInputStream(fileName); | |
ObjectInputStream ois = new ObjectInputStream(fis); | |
Object obj = ois.readObject(); | |
ois.close(); | |
List<TYPE> list = (List<TYPE>) obj; | |
for (TYPE type : list) { | |
System.out.println(type); | |
} | |
} catch (IOException e) { | |
} catch (ClassNotFoundException e) { | |
} | |
System.out.println("-----serialize individual-----"); | |
try { | |
FileOutputStream fos = new FileOutputStream(fileName); | |
ObjectOutputStream oos = new ObjectOutputStream(fos); | |
oos.writeObject(TYPE.INT); | |
oos.writeObject(TYPE.LONG); | |
oos.writeObject(TYPE.DATE); | |
fos.close(); | |
System.out.println("-----serialize finish-----"); | |
FileInputStream fis = new FileInputStream(fileName); | |
ObjectInputStream ois = new ObjectInputStream(fis); | |
Object obj; | |
while ((obj = ois.readObject()) != null) { | |
System.out.println((TYPE)obj); | |
} | |
ois.close(); | |
} catch (IOException e) { | |
} catch (ClassNotFoundException e) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment