This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem while reading from file  RSS feed

 
gaurav chhabra
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir i have following code


FileReader fr=new FileReader("dheeraj_chat.txt");
int ch;
StringBuffer st=new StringBuffer();
while((ch=fr.read())>0)
st=st.append((char)ch);
System.out.println("string new= "+st.toString());


this code i readingonly first line of the file .....not the rest of file...

plz tell me what to do

thank you
gaurav
 
Annie Smith
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it necessary to read character by character? You could try using a BufferedReader.




[ March 31, 2005: Message edited by: Annie Smith ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by gaurav chhabra:
While unlikely, if you have a \x00 (null character, not a literal '0' character) in your file, your loop will terminate early. You should change the loop condition toOf course, Annie's suggestion of using readLine() from BufferedReader will be easier and perform better.
[ March 31, 2005: Message edited by: David Harkness ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!