I need to read a remote file using a java app, but the file is in apache server on linux. I tried with "\\" but doesn't work like windows. How can i do that?
3 Answers
You'll need to use the URL class: http://download.oracle.com/javase/1.4.2/docs/api/java/net/URL.html
This is the standard way of reading files from a URL.
Comments
This depends on a number of things. But we don't really know what question you're asking. Are you asking how to retrieve a document over HTTP? How to do a file copy from Linux? Network shares?
If the file is served by the webserver (in the docroot), the easiest way is probably to request it over HTTP using the URL class as stated above.
If the file is NOT under the webroot (i.e. can't be specified as http://webserver.name/some/path/to/file) then you'll need to use some other method. I'm assuming this is what you meant - you mention \\, the Windows file-sharing (SMB) protocol prefix. The easiest way is to use SSH and scp/sftp, which is probably already installed on the Linux machine - you may need to enable it, and you'll need a login. Then it's as simple as scp user@host:/remote/file/path local/path. You can set up SSH keys to avoid a password.