• Post Reply Bookmark Topic Watch Topic
  • New Topic

I cannot use readLine for what I need to do  RSS feed

 
david jaco
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading a file that has certain lines that I would want to "extract" and perform some code on. These lines have a format like this:
"data1\rdata2\rdata3\r\n"
using the readLine of the BufferedReader I only get back "data1", but need everything from the beginning of the line to the \r\n, if this line contains certain search critera.
I have looked at the other read methods of other input classes, like FileReader, FileInputStream etc. I just cannot figure out how to get one line from data formated like above.
Any suggestions on how to do this will be appriciated.
I hope this is just a result of my inexperience in programming.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code that is reading the file? I'm not having any issue getting a line of data like that and printing it out. Shows everything to be there.
 
david jaco
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code, the file has
"data1\rdata2\rdata3\r\n
data4\r[/I/data5[I]\rdata6\r\n"
this code produces a string with just "data1" in it. I would like the string to have "data1\rdata2\rdata3" in it so I can split it by the \r.
Thanks for your help
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may have to write your own ReadLn by reading bytes and appending to a buffer until you find \n. I've not had to move files between Windows & Unix much, but they have different rules. Does Windows treat \r by itself as a newline?
 
rollyn moises
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your code is about writing not reading.
using readLine is fine.
 
Dhanush Dharsh
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using readLine() on BufferedReader returns the whole String unlike you had mentioned. I checked your code with a sample program and am getting the whole line. I tested it on windoz which OS are you using ?
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, definitely curious what system you are running it on. Is the line of data you are showing exactly as it appears in the file? And what type of file are you reading from? I'm curious if there might be some formatting that is being stuck in there that we're not seeing.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tested with linux and get only the first string (as expected).
 
david jaco
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using windows. I wrote a loop that uses read line to get the first part (up to the /r) then if it matches a certain critera, I readlines until I get a zero length line (the \n). Then I manipulate that string.
I appreciate all the help with this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!