我得到「系統找不到指定的路徑」。當我嘗試上傳一個圖像到資源內的項目文件夾。 這裏是我的項目結構:Spring Boot |將圖像上傳到資源中的相對路徑
|工程 | SRC |主 |資源 | META-INF.resources |圖片
Project Structural Hierarchy can be seen here in the image format.
我已經定義了路徑
String path = "\\resources\\images\\" + imageName; File file = new File(path);
try {
InputStream is = event.getFile().getInputstream();
OutputStream out = new FileOutputStream(path);
byte buf[] = new byte[1024];
int len;
while ((len = is.read(buf)) > 0)
out.write(buf, 0, len);
is.close();
out.close();
} catch (Exception e) {
System.out.println(e);
}
什麼是META-INF.resources director下images文件夾的確切路徑ÿ?
你試過'ServletContext'嗎? – fiskra
'String path = context.getRealPath(「resources/images」+ imageName);'應該在你得到'ServletContext'後應該可以工作 – fiskra