| | |
Read a text file from a website
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
I need to open a .txt file from a website. I tried this code:
but the program froze on me. What is the best way to do this?
Thanks!
Java Syntax (Toggle Plain Text)
int len = 0; FileReader fr = new FileReader("http://www.cinndev.com/testFile.txt"); BufferedReader br = new BufferedReader(fr); String str = ""; while ((str = br.readLine()) != null) { System.out.println(str); len++; }
but the program froze on me. What is the best way to do this?
Thanks!
try
Java Syntax (Toggle Plain Text)
try { // Create a URL for the desired page URL url = new URL("http://www.cinndev.com/testFile.txt"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String str; while ((str = in.readLine()) != null) { System.out.println(str); } in.close(); } catch (MalformedURLException e) { } catch (IOException e) { }
![]() |
Similar Threads
- Cant readline in text file.... URGENT help~ (VB.NET)
- newbie??? Including text files in html (HTML and CSS)
- help hosting website from home. (Domains and DNS)
- Audio Website Testimonial (Promotion and Marketing Plans)
- I Cannot Delete, Move, or Rename a File On My PC. (Viruses, Spyware and other Nasties)
- newbie needs help, basic mfc stuff (C++)
- Creating Auto-Responder in PHP (PHP)
- Help me please (C++)
Other Threads in the Java Forum
- Previous Thread: Need help with Servlets
- Next Thread: confusion with char datatype
Views: 2602 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database detection draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linux list loop map method methods mobile netbeans newbie number object objects oracle oriented os panel print problem program programming project projects recursion replaydirector reporting researchinmotion return robot scanner score screen se server set size sms socket sort sql stream string swing test threads time transfer tree ubuntu windows






