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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a file on a different machine. 1

Status
Not open for further replies.

lotsToLearn

Programmer
Jun 10, 1999
9
CA
Hi, <br>
<br>
I want to read a file that exists on a machine that is located on our network ( same subnet etc etc ). <br>
<br>
The machine is running IIS and the file exists at <br>
<br>
http:\\wjcalsrv8\tf-retired\data\log.txt <br>
<br>
I use the following code to create a handle to this file <br>
<br>
sourceFile = new File(&quot;\\\\wjcalsrv8\\tf-tired\\data\\log.txt&quot;);<br>
<br>
Then I check to see if the file exists and the result is always no. <br>
<br>
How can I set things up so that I can read a file from a machine in my network. <br>
<br>
Any and all help is appreciated. <br>
<br>
ALH<br>

 
Hi!<br>
<br>
The File class can be used only locally (with system-dependent path and file name).<br>
If you reach the computer with http, you should use the URL class to read the contents of a file, something like this:<br>
<br>
public static void main(String[] args) throws MalformedURLException,<br>
IOException {<br>
String s;<br>
<br>
URL urlTxt=new URL(&quot;http:\\wjcalsrv8\tf-retired\data\log.txt&quot;);<br>
InputStream in=urlTxt.openStream();<br>
DataInputStream din=new DataInputStream(in);<br>
while (true) {<br>
s=din.readLine();<br>
if (s==null) break;<br>
System.out.println(s);<br>
}<br>
in.close();<br>
}<br>
<br>
Good luck. Bye, Otto.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top