报了java.io.FileNotFoundException,请问有哪里错吗?网络路径不对吗?要怎么样的路径才是对的?
urlconnection那是发请求获取的,你这本地直接fileinputstream就行了
应该是你的path错了,按照你的写法,new File(path) 的 path 应该是本地的一个路径地址,如:D://file//xxx
其实你如果要做下载的话,给你一点其他的办法
1.IO流
response.setContentType("application/octet-stream");
response.addHeader("Content-disposition", "attachment;filename=" + path.substring(path.lastIndexOf("/")));//此处名称自己定
OutputStream outputStream = null;
HttpURLConnection conn = null;
InputStream inputStream = null;
try {
outputStream = response.getOutputStream();
File file = new File(本地路径);
inputStream = new FileInputStream(file);
IOUtils.copy(inputStream, outputStream);
} catch (Exception ex) {
//自己定义
} finally {
IOUtils.closeQuietly(inputStream);
IOUtils.close(conn);
IOUtils.closeQuietly(outputStream);
}
2.通过WebMvcConfigurationSupport
registry.addResourceHandler("/file/**")
.addResourceLocations("file:" + 本地文件目录);