943,718 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1693
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Dec 13th, 2008
0

help me to read a file from another machine in the network.

Expand Post »
haii
I have a requirement in which i want to read a file from another
machine in the network.
I want to know how to set the URL

Thanks in advance
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
ajithraj is offline Offline
71 posts
since Jan 2008
Dec 13th, 2008
0

Re: help me to read a file from another machine in the network.

And how exactly is the target file shared on the network ?? FTP, HTTP ?? or just by SMB (Windows Sharing) ??

You need to divulge more details as to what exactly are you trying to achieve.

Also although I know its useless saying this but still read this essay and learn how to frame your questions on a forum like this, it is you who will benefit most because if you ask questions correctly or ask the correct questions, more people will feel like answering to your query.
Last edited by stephen84s; Dec 13th, 2008 at 9:28 am.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Dec 13th, 2008
0

Re: help me to read a file from another machine in the network.

As mentioned above how is the file shared ? But more importantly whats this got to do with Java ? Please put your question in proper context so that we are able to understand and in turn help you better.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Dec 15th, 2008
0

Re: help me to read a file from another machine in the network.

really Sorry .....and thanks for answering me....

I want to read an image from a machine in network using http...
Actually my need is to read the image from a system and to store this in another one
I know that it can be done only by setting the Url..


///verruckt24:::But more importantly whats this got to do with Java ?
I dont understand this...i want to access this from a java class
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
ajithraj is offline Offline
71 posts
since Jan 2008
Dec 15th, 2008
0

Re: help me to read a file from another machine in the network.

Quote originally posted by ajithraj ...
///verruckt24:::But more importantly whats this got to do with Java ?
I dont understand this...i want to access this from a java class
Verruckt asked that because you simply had forgotten to mention that fact.

Quote originally posted by ajithraj ...
I know that it can be done only by setting the Url..
I do not what you are talking about here, but to access files over HTTP you will definitely be needing the URL and URLConnection classes. They can be used connect to URLs over an HTTP connection.

Here is an example that deals with text files.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Dec 15th, 2008
0

Re: help me to read a file from another machine in the network.

Thanksss.. But i still have problems..


The code i wrote is :::
URL hp = new URL("http", "www.rediff.com", 80, "/");
URLConnection hpCon = hp.openConnection();


but hpCon.getContentLength() = -1....
It means that No Content is Available....

why this happens...
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
ajithraj is offline Offline
71 posts
since Jan 2008
Dec 15th, 2008
0

Re: help me to read a file from another machine in the network.

To quote the Javadocs of URLConnection to which I had already linked to in the previous post :

Quote ...
1. The connection object is created by invoking the openConnection method on a URL.
2. The setup parameters and general request properties are manipulated.
3. The actual connection to the remote object is made, using the connect method.
4. The remote object becomes available. The header fields and the contents of the remote object can be accessed.
So you need to first connect and then check whether the content is available.
Last edited by stephen84s; Dec 15th, 2008 at 2:58 am.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Dec 15th, 2008
0

Re: help me to read a file from another machine in the network.

java Syntax (Toggle Plain Text)
  1. public void URLReader(){
  2. try{
  3. URL logic = new URL("http://your host name & port number/folder/");
  4. BufferedReader in = new BufferedReader(new InputStreamReader(logic.openStream()));
  5.  
  6. String inputLine;
  7.  
  8. while ((inputLine = in.readLine()) != null)
  9. System.out.println(inputLine);
  10.  
  11. in.close();
  12. }
  13. catch (MalformedURLException e) {
  14. System.out.println ("Malformed URL= "+e);
  15. }
  16. catch (IOException e) {
  17. System.out.println ("IO Exception = "+e);
  18.  
  19. }
  20.  
  21. Albert
  22. }
Last edited by cscgal; Dec 15th, 2008 at 6:08 pm. Reason: Added code tags
Reputation Points: 9
Solved Threads: 2
Light Poster
AlbertPi is offline Offline
33 posts
since Nov 2008
Dec 15th, 2008
0

Re: help me to read a file from anothermachine in the network.

AlbertPi, please use [code] [/code] tags if you are going to post code examples.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Dec 16th, 2008
0

Re: help me to read a file from another machine in the network.

okk...this is what i too is trying now..but since my connection is through a proxy server i want to add its IP..but the problem is that how can i get the IP adress of my proxy server...

Thanks..
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
ajithraj is offline Offline
71 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: a beginner in java needs help
Next Thread in Java Forum Timeline: Intranet aplication





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC