0
我是Spring MVC的新手。我創建接受一個FileOutputStream中並如下寫入XML到一個新的彈簧控制器的方法:Spring FileNotFoundException ..(沒有這樣的文件或目錄)
@RequestMapping(value = "/xml", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
public final void getMappingsAsXML(HttpServletResponse response) {
Customer customer = getCustomerMappings();
try {
// Generates xml file
xmlHelper.save(customer, new StreamResult(new FileOutputStream("/WEB-INF/content/customermapping.xml")));
// print to browser
// read generated file and write to response outputsteam
} catch (XmlMappingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
然而,上述代碼拋出以下例外:
java.io.FileNotFoundException: /WEB-INF/content/customermapping.xml (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:84)
內容目錄已經存在於WEB-INF文件夾。另外,有沒有更好的方法在春季寫文件到瀏覽器?
[順便說一句,我使用maven]
您想從應用程序相關文件讀取/寫入。這就是說,我不會把它放在那裏。哦,馬特已經說了這些 - 廢話。 –