2015-04-01 49 views
0

我的春天啓動的項目結構是這樣的寫文件到春季啓動文件夾

SRC
| - 主
| - | -java
| - | -resources
靜態
| -CSS
| -images
| -js

現在我想將文件寫入到靜態/ images文件夾 我嘗試新的文件中像 BufferedOutputStream stream =new BufferedOutputStream(new FileOutputStream(new File("static/images")));它會拋出"No such file or directory" exception

,但在其他的html文件,我可以通過"js/jsFile.js"得到JS

回答

2

new File("static/images")是正確的
我用new File("/static/images")所以我得到一個異常

0

我是在使用Spring Boot的情況下,我不得不將圖像保存到靜態訪問的一個目錄中。

下面代碼工作完美

byte[] imageByteArray .... 
String fileName = "image.png"; 
String fileLocation = new File("static\\images").getAbsolutePath() + "\\" + fileName; 
FileOutputStream fos = new FileOutputStream(fileLocation); 
fos.write(imageByteArray); 
fos.close(); 

希望它幫助。