【发布时间】:2018-06-12 10:57:05
【问题描述】:
我正在尝试将图像复制到 WEB-INF 文件夹内的 assets 文件夹中。以下代码成功将图像复制到项目外,但无法复制到 WEB-INF 文件夹内。
public static void copyFile(String source, String destination) throws IOException {
try {
File sourceFile = new File(source);
File destinationFile = new File(destination);
FileInputStream fileInputStream = new FileInputStream(sourceFile);
FileOutputStream fileOutputStream = new FileOutputStream(destinationFile);
int bufferSize;
byte[] bufffer = new byte[512];
while ((bufferSize = fileInputStream.read(bufffer)) > 0) {
fileOutputStream.write(bufffer, 0, bufferSize);
}
fileInputStream.close();
fileOutputStream.close();
} catch (IOException e) {
throw new IOException(e.getMessage());
}
}
我从Http请求中得到了一个图片路径。
CopyFile.copyFile(imageUrl, "http://localhost:8080/M.S.-Handloom-Fabrics/static/"+imageName+".png");
我已经在 dispatcher-servlet.xml
中映射了资源<mvc:resources mapping="/static/**" location="/WEB-INF/assets/"/>
这是错误
信息:http:\localhost:8080\M.S.-Handloom-Fabrics\static\TueJun1216_27_54NPT20180.png(文件名、目录名或卷标语法不正确)
【问题讨论】:
标签: image spring-mvc copy