• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with leading whitespaces  RSS feed

 
Eugene Kanshin
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
I trying to read data from text file row by row:

try {
BufferedReader reader = new BufferedReader(new FileReader(datafile));
String str = null;
while((str = reader.readLine()) != null) {
System.out.println(str);//for testing
} catch (IOException ex) {
ex.printStackTrace();
}
The problem is that in my file (datafile) there are leading whitespaces in some rows, but str ignores them (starts with text).
Could you help me with this problem?
I'd like to keep these whitespaces in str.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange, it works for me. I guess the question might be what is the format of your "datafile"? Is it plain text?

[ January 19, 2007: Message edited by: marc weber ]
 
Eugene Kanshin
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry. You are completely right.
I just found that there was str.trim() in my code.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eugene Kanshin:
...I just found that there was str.trim() in my code.

That would do it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!