| | |
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
| Thread Tools | Search this Thread |
android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component database db defaultmethod development dice dragging draw ebook eclipse error event exception formatingtextintooltipjava fractal game givemetehcodez graphics gui hql html ide image infinite input integer invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie numbers openjavafx oracle parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads time tree windows






