How to store files in client machine?

空扰寡人 提交于 2019-12-12 03:47:20

问题


File dir = new File(System.getProperty("user.home")+"\\Desktop\\" + svc);
        dir.mkdir();
        File f;
        f = new File(System.getProperty("user.home")+"\\Desktop\\" + svc
                + "\\" + logFile + "_" + System.currentTimeMillis()
                + ".txt");

I am using this code to store the files in the user(client) machine.But it is storing the files in the server machine.Can anyone help me on this? I have deployed my war file in unix server.


回答1:


Saving a file on a client machine from software running on a server is not as simple as that.

Servers do not have direct access to the file system of any client - it would be very insecure if that were the case.

The simplest way to do this is by making the server return a web page with a link which the user can click to download the file.

You could also do something more complicated, for example write an applet that downloads the file (using some file transfer protocol) and saves it in the local file system. The applet would need to have the appropriate permissions (by default, applets cannot access the local file system).




回答2:


Seems like this code is part of a Web Application Server Side. In this case System.getProperty("user.home") will return Server's home directory.



来源:https://stackoverflow.com/questions/15652986/how-to-store-files-in-client-machine

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!