• Post Reply Bookmark Topic Watch Topic
  • New Topic

error in retrieving from file.

 
gayathri murugesan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


tha actual contents of the file is

business
personal

but my output is

THE CONTENTS FROM FILE IS:usiness
THE CONTENTS FROM FILE IS:personal

so that when i enter business it doesn't go in to the loop which checks for equality.

please help.


 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first character is eaten by the "check=reader1.read()" statement. I don't think you need that anyway - you can check the file for being empty via "myF.length() == 0".
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the Javadocs for BufferedReader's read() method: what do you expect to happen?
 
gayathri murugesan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would like to retrieve the contents from folderwithmsg.txt file and then compare with the fileName given by user.if the filename is not present in the text file,i should write in the text file.otherwise i should not.as the first character is being omitted,whenever the filename equals the first name in the text file ,it is writing in the file.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You were already told why the first character is being read, given a link to the documentation to prove it, and provided a workaround--what else do you need?
 
gayathri murugesan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with length method also i m getting the same type of problem.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I think you should take a step back and re-examine the problem, and the hints you've been given.
 
pramod reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello gayathri murugesan ;

just go through my code and find mistake..
this code is working........
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!