Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a remote file?

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
Hi all,

Can I use the File class to open a remote file that doesnt exists locally be appending the file name?

Thanks
 
You can do that if the file is on a mapped drive as any regular file.

And you can also download a file with http using Java

Cheers,
Dian
 
(But not just by prefixing the file name with " though)

You would need to use java.net.HttpUrlConnection to download a resource from an HTTP server.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
You could use the class URL to read a file:

Code:
	String surl = "[URL unfurl="true"]http://home.arcor.de/hirnstrom/index.html";[/URL]
	URL url = new URL (surl);
	BufferedReader br = new BufferedReader (new InputStreamReader (url.openConnection ().getInputStream ()));

	String line = "";
	do
	{
		line = br.readLine ();
		if (line != null) System.out.println (line);
	}while (line != null);


seeking a job as java-programmer in Berlin:
 
Bearing in mind that :

url.openConnection ().getInputStream ();

equates to using the HttpUrlConnection object :

HttpUrlConnection huc = (HttpUrlConnection)url.openConnection();
InputStream is = hic.getInputStream();

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top