Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BufferedReader.readLine() method.

 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to read a file line by line and put it in different variables depending upon some condition.
I am using,
BufferedReader para;
while((line = para.readLine()) != null)
two of the lines in paragraph are
1. this is suresh's
2. key for the home.
wheen i read line 1 and print the line i see that
line = "this is suresh''s"
note that ' has been appended by one more '.
Why is that ?
If i dont want that to happen. what should i be doing?
thnaks.
Such case can happen only one in while in along paragraph.

Thanks!!
 
Sigfred Zamo
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I�ve remade a similar example:

having pr.txt:

and the output:

(it works ok for me..)
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sigfred!!
oops !! I did not mention that my para is defined this way.
BufferedReader para = new BufferedReader(new InputStreamReader(stream));
Is there any way that without changing this i get the proper output?
Thanks!!
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Building off this example, I compiled the following:

And again, the output comes out as "Saresh's", single quote. What is your variable stream representing?
 
Sigfred Zamo
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I tried this way:

..and I got the same result..
try copypasting your code..
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oho...
I did not realise that Sigfred is suggesting that
your code should give result you want as is!!

Sorry guys I see that the get method from some one elses class which i am using here seem to be producing my problem (never trust blindly
Thanks for all your responses.....
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone point me to a method to replace
'' marks from a string with single '
e. g
suresh''s key is in the room near mahesh''s room.
should produce result,
suresh's key is in the room near mahesh's room.
 
Doanh Nguyen
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I asked a similar question recently:
http://www.coderanch.com/t/391421/java/java/Replace-substring
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Doanh!!
That was very helpful link...
It saved lot of my time....
Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic