aspose file tools*
The moose likes Servlets and the fly likes Accessing file on remote windows share Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Accessing file on remote windows share" Watch "Accessing file on remote windows share" New topic
Author

Accessing file on remote windows share

Femi Byte
Ranch Hand

Joined: Jul 09, 2004
Posts: 40
I need to write a servlet that will access a file on a remote windows share - either by redirection or downloading the file. Anyone have any pointers to this?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What part are you stuck on?
Have you tried yet?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Femi Byte
Ranch Hand

Joined: Jul 09, 2004
Posts: 40
I guess my question would be how to access it? I can't do a straightforward redirection since the file is not accessible via http.
In other words, how can I use a servlet to access a file I'd normally access via Windows Explorer using a path of this form:

\\hostname\dir1\filename.log

?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You should be able to access that file from your servlet app with the UNC name (the syntax you're using). From there, you could stream the file to the browser from a servlet.

I have a simple webapp example that streams image files to the browser.
That might get you started.
http://simple.souther.us/SimpleStream.war.

In that app, I'm using Context.getRequestAsStream to read the files.
In your case you would want to use a file reader java.io.FileReader.

One thing to watch for:
If your webserver is running as a Windows service, the user under which it is running may not have sufficient permissions to read network files.
You'll either need to alter that user's rights or run the service as a different user.
Femi Byte
Ranch Hand

Joined: Jul 09, 2004
Posts: 40
Ok, I'll take a look at it, thanks much.
 
 
subject: Accessing file on remote windows share