二级JAVA第六章辅导:Java串行化

文章作者 100test 发表时间 2007:04:06 21:25:23
来源 100Test.Com百考试题网


1. 串行化例子一
ObjectInputStream和ObjectOutputStream。

public class SerializationDemo {

public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Vector list.

BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in)).
System.out.print("Checking for previous serialized list").

try {
FileInputStream fin = new FileInputStream("list.out").

ObjectInputStream oin = new ObjectInputStream(fin).

try {
Object obj = oin.readObject().
list = (Vector) obj.

} catch (ClassCastException e) {
// TODO: handle exception
list = new Vector().
} catch (ClassNotFoundException e){
list = new Vector().
}
fin.close().

} catch (FileNotFoundException e) {
// TODO: handle exception
list = new Vector().
}

for (..){
System.out.println("Menu :-").
System.out.println("1.. Add item").
System.out.println("2.. Delete item").
System.out.println("3.. List items").
System.out.println("4.. Save and quit").
System.out.println("Choice").

String response = reader.readLine().
int choice = Integer.parseInt(response).

switch (choice) {
case 1:
System.out.print("Enter item : ").
String item = reader.readLine().
list.addElement(item).


相关文章


澄清Java语言接口与继承的本质
Java语言的接口与类型安全
二级JAVA第六章辅导:Java串行化
二级JAVA第五章辅导:条件控制
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛