【发布时间】:2014-03-03 15:50:23
【问题描述】:
当我调试下面的代码时,它会在properties.store(fos, "none") 线上抛出一个FileNotFoundException,有什么具体原因吗?
编辑:堆栈跟踪是指以下内容:
Exception(Throwable).<init>() line: 249 [local variables unavailable]
Exception.<init>() line: not available
Thread.getStackTrace() line: not available
JCP.WriteVariablesHashmap(HashMap<String,Object>) line: 51
JCP.NewMethod(String[]) line: 133
JCP.InteractiveMode(String[]) line: 165
JCP.BatchOrInterActive(String[]) line: 96
Main.main(String[]) line: 13
代码:
public void WriteVariablesHashmap(HashMap<String, Object> hashMap){
try {
File file=new File("Variables.ser");
FileOutputStream fos = null;
Properties properties = new Properties();
fos=new FileOutputStream(file);
for (Map.Entry<String,Object> entry : hashMap.entrySet()) {
properties.put(entry.getKey(), entry.getValue());
}
System.out.println(file);
properties.store(fos, "none");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
【问题讨论】:
-
你能发布完整的堆栈跟踪吗?
-
FileOutputStream constructor 会因各种原因抛出该异常。
-
如何获得完整的堆栈跟踪?代码没有到达 catch 块。