【发布时间】:2013-08-22 11:05:32
【问题描述】:
我正在尝试将二进制文件写入指定文件夹,但它一直给我一个异常。 例如,如果我在不指定任何文件夹的情况下写入文件,程序将毫无问题地写入:
public void saveFile(String name) throws IOException {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(name + ".bin"));
out.writeObject(this);
out.close();
}
但是,当我尝试指定文件夹时,程序不会写入文件:
public void saveFile(String name) throws IOException {
File location = new File("/path/" + name + ".bin");
FileOutputStream fos = new FileOutputStream(location);
ObjectOutputStream out = new ObjectOutputStream(fos);
out.writeObject(this);
out.close();
fos.close();
}
我尝试了几种不同的方法,但仍然没有解决方案。 有人知道我做错了什么吗?
【问题讨论】:
-
写堆栈跟踪
标签: java serialization fileoutputstream