Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing file on remote windows share

 
Femi Byte
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What part are you stuck on?
Have you tried yet?
 
Femi Byte
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I'll take a look at it, thanks much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic