Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

BufferedReader removing spaces?

807589Jul 30 2008 — edited Jul 31 2008
I've got a text file thats a database of sorts, however rather than the different columns being seperated by commas as would be preferred, it is formatted only through spacing. For example, the first few lines are something like
001  Paul  4
002 James 44
When I use BufferReader to parse lines of text it removes the excess spaces so that the resulting strings are
001 Paul 4
002 James 44
This presents a number of problems for me to distinguish the columns, because there are some places in the file that the columns aren't even separated by spaces, and the only way to tell that it's a new column is by knowing how many characters into the line it is. Is there anyway to read in the data from this text file without the spaces seemingly being removed? I tried using the read() function rather than readLine() to try and make sure that I got every byte, but still the extra spaces seemingly got deleted. My code is:
BufferedReader input = new BufferedReader(new FileReader("text.txt"));
String [] team = new String[15];
String line = "";

//read the first 15 lines
for (int i=0; i<15; i++) {
	//607 is the number of characters in each of the lines.
        for(int k=0; k<607; k++){ 
       	  	line+=(char)input.read();
	}
	team=line;
System.out.println(team[i]);
line="";
}
Thanks in advance for any help,
Repole

Edited by: Repole on Jul 30, 2008 8:10 PM

Edited by: Repole on Jul 30, 2008 8:10 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2008
Added on Jul 30 2008
31 comments
6,405 views