【发布时间】:2017-05-09 11:43:01
【问题描述】:
我得到“系统找不到指定的路径。”当我尝试将图像上传到资源中的项目文件夹时。 这是我的项目结构:
|项目 |源 |主要 |资源 |META-INF.资源 |图片
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 目录下 images 文件夹的确切路径是什么?
【问题讨论】:
-
你试过`ServletContext`了吗?
-
String path = context.getRealPath("resources/images" + imageName);应该在你得到ServletContext后工作
标签: spring file-upload spring-boot image-uploading relative-path