62,614
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
import java.util.*;
import java.awt.*;
public class SavePoint {
public static void main(String[] args) {
String s = "one";
Point p = new Point(66,88);
HashMap<String,Point> hm = new HashMap<String,Point>();
hm.put(s,p); //向容器中放对象
try{
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("c:/
test.txt"));
oos.writeObject(hm.get(s)); //从容器中取数据并输出到文件中
oos.flush();
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("c:/
test.txt"));
Point rp = (Point)ois.readObject(); //从文件中读出数据
System.out.println("" + rp.getX() + " " + rp.getY());
ois.close();
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
} catch(ClassNotFoundException e) {
e.printStackTrace();
}
}
}