我得到“系统找不到指定的路径”。当我尝试上传一个图像到资源内的项目文件夹。 这里是我的项目结构: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