java io 读写对象

来源:互联网 发布:linux 端口映射工具 编辑:程序博客网 时间:2024/04/28 19:57
<span style="font-size:14px;">private static void writeOBJ() {File file = new File("/Users/liqingfeng/Desktop/test");FileOutputStream fos;try {fos = new FileOutputStream(file);ObjectOutputStream oos = new ObjectOutputStream(fos);String str = new String("我啊你 abc123..");oos.writeObject(str);oos.close();fos.close();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}private static void readOBJ() {File file = new File("/Users/liqingfeng/Desktop/test");FileInputStream fis;try {fis = new FileInputStream(file);ObjectInputStream ois = new ObjectInputStream(fis);String str = (String) ois.readObject();System.out.println(str);ois.close();fis.close();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} catch (ClassNotFoundException e) {e.printStackTrace();}}</span>

0 0
原创粉丝点击