下面是我编写的用于下载文件的代码, 现在我需要将文件下载到客户端系统中的特定位置。我将通过用户的输入获取路径。 我知道弄乱客户端系统不好,但我不得不这样做
//setting the content type of response
response.setContentType("application/"+strFileType);
response.setHeader("content-disposition","attachment; filename="+strFileName+"."+strFileType);
//creating a file input stream object
InputStream input = blob.getBinaryStream();
//declaring a variable
int i;
while((i=input.read())!=-1)
{
//writing output
printWriter.write(i);
}
//closing the streams
input.close();
printWriter.close();
最佳答案
I know it's not good to mess client system but I had to do that ....
好消息(从用户的角度来看!)是您无法做到这一点。即使你“必须”。网络浏览器是专门为阻止您(服务器端)执行此类操作而构建的。
解决这个问题的唯一方法是在受信任的浏览器插件或小程序或用户必须专门安装在他/她的计算机上的东西中实现该功能。
... where to use the path taken from the user and i'm programming this just like ftp but server side is a database
问题在于,浏览器无法判断您这样做是否出于合法目的……或者是试图破坏系统/用户文件、植入恶意软件或可能<的任何其他事情 对用户有害。
它不会冒让你这样做的风险,这是一件好事。
关于java - 将文件下载到客户端系统中的特定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13427895/