求助,Java下载功能的代码怎么无法弹出浏览器的下载框? 5
Filefile=newFile(filePath);StringfileName=filePath.substring(filePath.lastIndexOf(Fil...
File file = new File(filePath);
String fileName = filePath.substring(filePath.lastIndexOf(File.separator) + 1);// 得到文件名
fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");
System.out.println("fileNam="+fileName);
response.setContentType("application/octet-stream");
response.addHeader("Content-Disposition", "attachment;filename="+ fileName);
String len = String.valueOf(file.length());
response.setHeader("Content-Length", len);// 设置内容长度
OutputStream out = response.getOutputStream();
FileInputStream in = new FileInputStream(file);
byte[] b = new byte[1024];
int k;
while ((k = in.read(b)) != -1) {
out.write(b, 0, k);
}
in.close();
out.close(); 展开
String fileName = filePath.substring(filePath.lastIndexOf(File.separator) + 1);// 得到文件名
fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");
System.out.println("fileNam="+fileName);
response.setContentType("application/octet-stream");
response.addHeader("Content-Disposition", "attachment;filename="+ fileName);
String len = String.valueOf(file.length());
response.setHeader("Content-Length", len);// 设置内容长度
OutputStream out = response.getOutputStream();
FileInputStream in = new FileInputStream(file);
byte[] b = new byte[1024];
int k;
while ((k = in.read(b)) != -1) {
out.write(b, 0, k);
}
in.close();
out.close(); 展开
1个回答
展开全部
答案是不能。如果是智能机一定支持Java功能,还另外支持像sis,sisx,exe等格式的,既然连Java功能不支持的,那么该手机就什么软件都没得下载安装的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询