URL Stream Text in java?
-
Hello am trying to make a news feed am having problems making a loop that displays next line in a text file. i can only make it go though first line i tryed alot of things i tryed making a array list and display like that. nothing worked. anyone can help me try { URL url = new URL("http://test.txt");//news url BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream())); String arraylist = br.readLine(); if(arraylist != null) this.news = arraylist; } catch(Exception e){e.printStackTrace();} } I tryed diffent ways like this: this one displays nothing. not even first line like the first URL url = new URL ("news.txt"); URLConnection uc = url.openConnection( ) ; BufferedReader br = new BufferedReader(new InputStreamReader ( uc.getInputStream( ) ) ); while(true) { String line = br.readLine( ) ; if (line==null) break; System.out.println(line); }
-
Answer:
Try this first just to make sure you're seeing any data from your stream. This reads in characters without worrying about the newline. Note that if you have binary (non-text) data coming from your stream, you console is going to make weird beeps. char[] data=new char[1024]; int cnt=-1; while((cnt=br.read(data)!=-1) { System.out.write(data,0,cnt); } BTW, the best idiom for reading from a BufferedReader is this: String line=null; while((line=br.readLine())!=null) { ... }
Andreas at Yahoo! Answers Visit the source
Related Q & A:
- How to Implement Gateway Service something similar to Oracle API gateway Using Java and Java based Open Source frameworks only?Best solution by Quora
- How to get live stream url from youtube live?Best solution by Stack Overflow
- How do I retrieve a URL in Java?Best solution by Stack Overflow
- How to search for a particular string in a text file using java?Best solution by Stack Overflow
- What does URL mean when I am asked for the URL while reporting abuse yahoo?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.