java.io.FileNotFoundException: https:\www.xxxx.com\xxx\files\12.doc (文件名、目录名或卷标语法不正确。)
路径没有错阿,而且域名变成 "https:\www.xxxx.com" 少了一"\"了
我下载附件的代码
StringBuilder filePath = new StringBuilder("https://www.xxxx.com" + request.getParameter("filePath"));
try {
// 建立链接
URL httpUrl = new URL(filePath.toString());
HttpURLConnection conn = (HttpURLConnection) httpUrl.openConnection();
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setDoOutput(true);
// post方式不能使用缓存
conn.setUseCaches(false);
//连接指定的资源
conn.connect();
//获取网络输入流
InputStream inputStream = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(inputStream);
FileOutputStream fileOut = new FileOutputStream(filePath.toString());
BufferedOutputStream bos = new BufferedOutputStream(fileOut);
byte[] buf = new byte[4096];
int length = bis.read(buf);
//保存文件
while(length != -1){
bos.write(buf, 0, length);
length = bis.read(buf);
}
bos.close();
bis.close();
conn.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
https:\www.xxxx.com\xxx\files\12.doc 这也不是一个文件路径而是一个URL啊