[java] FileReader work on shared network files?

Started by
1 comment, last by Jimfing 16 years, 11 months ago
Hi i'm trying to use a FileReader on a file that is shared over my local network. Under linux, the path to the file is: smb://home/projects/test.txt However, with the code: File f = new File("smb://home/projects/test.txt"); FileReader fr = new File(f); It fails to find the file. Something odd I have noticed is that looking at 'f', it has changed the path to remove the double // after 'smb:'. Not sure if this is related to the problem though. Thanks.
Advertisement
Well, this issue goes a bit deeper than that. First, if you want a 'quick' solution (yet not the optimal one), you can mount a local folder to 'point' to the remote folder containing the file, like this (edit /etc/fstab):

//10.1.1.1/remoteFolder    /home/rodrigo/localFolder smbfs  credentials=/home/rodrigo/.smbcredentials    0    0


Where "smbcredentials" is a plain text file containing your username and password:

username=foopassword=bar


Well, not much help, eh? I bet you already know that :p Down to the Java stuff, then. AFAIK, you cannot deal with the SMB protocol with a URLConnection. I may be wrong though, but if I'm not, there may be a third party solution for that out there, open source or not.

In either case, all you have to do is open the connection to the remote file, and read it like a normal input stream or file channel. I've never done it myself, but if you can indeed use a URLConnection to access a SMB url, then I see no reason why it wouldn't work (other than, a potential problem with aforementioned credentials ;)

[edit: so many ugly typos and grammar errors... =]
a.k.a javabeats at yahoo.ca
Thanks for the info! I'll probably go with the 1st suggestion.

Jim

This topic is closed to new replies.

Advertisement