aspose file tools*
The moose likes Servlets and the fly likes How to write a file to local machine? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to write a file to local machine?" Watch "How to write a file to local machine?" New topic
Author

How to write a file to local machine?

Gudavy Hu
Greenhorn

Joined: Apr 11, 2002
Posts: 7
The application is running on Server "A", I am working on client machine "B". How to write a file to the directory of local machine (for example, c:\myDoc)?
If using File and FileWriter (or FileOutputStream), it can not work cross network. So file is write to the Server "A" instead of Client machine "B". If using ServletResponse.getOutputStream(), no file directory can be specified.
How can I do that?
Thanks a lot.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Short answer: you can't. This is not strictly a SErvlet or JSP thing, its a HTTP security thing.
Otherwise visiting a web page could result in people writing viruses, overwriting properties, or even have Microsoft detect a Linux operating system and overwrite it with Windows
One thing you can do is have someone make a request to a Servlet, then have the Servlet return a file to the client. The default for web pages is to return content with the mime-type of text/html and for the browser to handle this (by showing it on the screen)
There are other mime-types that browsers can handle (like images and movies), but if the browser doesn't know what to do with the file, it will prompt the user to save it on the harddrive (and they get to decide where to save it).
This isn't a complete solution (and may not work cos I ripped from the middle of an existing class) but it should give an idea... The only tricky bit is the Disposition Header, which changes the name of the file to the real filename.

Dave
mustang india
Ranch Hand

Joined: Feb 05, 2002
Posts: 60
One thing u can do is to have a digital signature. This means asking the client to give permissions to access his machine. If the client accepts, then the server can be able to do IO operations on the client machine.
Zakaria Haque
Ranch Hand

Joined: Jan 02, 2002
Posts: 60
Originally posted by David O'Meara:

Otherwise visiting a web page could result in people writing viruses, overwriting properties, or even have Microsoft detect a Linux operating system and overwrite it with Windows

... and charge the webmaster for licence and consulting fees


tobe bondhu nouka bherao<br />shonabo gaan aj shara raat
Gudavy Hu
Greenhorn

Joined: Apr 11, 2002
Posts: 7
Thanks to all your guys!
mustang india
Ranch Hand

Joined: Feb 05, 2002
Posts: 60
There are lots of commercial digital sinatures available in the market. U have to include this in ur applet/html (client). When the page loads, it will prompt the user to grant permissions for IO. U can get more technical info on this in the web. I have used this long back and I really dont remember it now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to write a file to local machine?