这里要进行正斜杠转成反斜杠的处理 JAVA中如何把反斜杠替换成正斜杠
str.replace("//","/");
String src=new String(inf1.getFilesrc().getBytes("iso-8859-1"),"gb2312");
System.out.println(src);// F:/工作项目/404.jpg
String mm=src.replace("//","/");
response.sendRedirect(mm); 结果是http://location/F:/sdd/404.jpg
到底要怎么样才能下载呀
answer:
out.clearBuffer(); // 如果使用JSP,需要加上这一句
OutputStream os = response.getOutputStream(); // 页面输出流,jsp/servlet都可以
String filename="d:/a.rar";
int lastdot = filename.lastIndexOf("/");
String name2 = filename.substring(lastdot);
String downname=filename.substring(lastdot+1); //下载的时候显示出什么名字
response.addHeader("Content-Disposition", new String(("attachment; filename=" + downname).getBytes("GBK"),
"ISO-8859-1")); // 针对中文文件名
File f = new File(filename); // 你的文件
InputStream is = new FileInputStream(f); // 文件输入流
byte[] bs = new byte[1024]; // 读取缓冲区
int len;
while((len=is.read(bs))!=-1){ // 循环读取
os.write(bs,0,len); // 写入到输出流
}
is.close(); // 关闭
os.close(); // 关闭
呵,上传到服务器(http://www.pp.com)上一样可以下载服务器上的文件(些时服务器相当于本地了)