• Post Reply Bookmark Topic Watch Topic
  • New Topic

how read a file text from internet ?

 
marco tognoni
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I want to read a text file from URL,
how can I do it ?
thanks
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can follow this steps:
Create your proper URL instance: URL target=new URL(the_file_address);
Make an URLConnection urlc=New URLConnection(myURL);
Get the text file as a stream you can read/save/etc... with
urlc.getInputStream();
You can also get the same InputStream from your URL instance with openStream().
-HTH
 
marco tognoni
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do what you told me,
but it goes error:
java.net.NoRouteToHostException: No route to host: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:295)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:161)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148)
at java.net.Socket.connect(Socket.java:425)
at java.net.Socket.connect(Socket.java:375)
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us your code...
Rene
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've made a code sample:

hope this helps
Rene
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You get this error messages because you are doing something wrong, take a look at how Rene uses the URL, URLConnection classes in the example above.
Check you write the address properly (http://...)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!