将文件下载到客户端系统中的特定位置

时间:2012-11-17 05:10:47

标签: java security file-upload file-io download

下面是我写的代码我要下载文件, 现在我需要将文件下载到客户端系统中的特定位置。我将获得用户输入的路径。 我知道混淆客户端系统并不好,但我必须这样做

        //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();

3 个答案:

答案 0 :(得分:4)

  

我知道混淆客户端系统并不好,但我必须这样做....

好消息(从用户的角度来看)是你无法做到的。即使你“必须”。 Web浏览器专门用于阻止您(服务器端)执行此类操作。

唯一可以解决的问题是在TRUSTED浏览器插件或applet中实现功能,或者用户必须在他/她的机器上专门安装的功能。


  

...在哪里使用从用户获取的路径,我正在编程,就像ftp,但服务器端是一个数据库

问题是浏览器没有办法判断你是出于合法目的这样做......还是试图破坏系统/用户文件,植物恶意软件或可能<的其他任何东西/ em>对用户有害。

不会冒这个让你这么做的风险,这是一件好事。

答案 1 :(得分:1)

这需要更新浏览器的文件下载位置,[注意:如果我们更新,则所有文件都将下载到该路径]

参考以下链接,您可能会得到这个想法:

How to change the download folder destenation in firefox?

How to check the location of download folder programmatically in browsers like Safari, Firefox etc on Mac?

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6ff178a2-5131-43d4-b4c0-efb4a2112e95

答案 2 :(得分:0)

如果您在Intranet内并且可以信任服务器,请使用具有授予访问权限的applet或类似技术......但再一次这真的很糟糕。