62,621
社区成员
发帖
与我相关
我的任务
分享
File file = new File("F:/test/file.dat");
InputStream is = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(is);
File f = (File)ois.readObject();
System.out.println(f.getName());


public static void main(String[] args) throws Exception{
File file = new File("C:\\Users\\zy\\Desktop\\tt.txt");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(file);
byte[] bs = baos.toByteArray();
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bs));
File f = (File)ois.readObject();
System.out.println(f.getName());
}