• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem while reading from file

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Do not threaten THIS beaver! Not even with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic