Strange spaces when using BufferedReader

R

rkr

Dear all
I have a strange problem when using BufferedReaders.
I want to read the following file:
8-20-29.26 49-46-02.05
8-20-28.19 49-45-55.52
8-20-30.46 49-46-05.15
....

//***code****
BufferedReader bReader = new BufferedReader(new FileReader(filename));
String line = bReader.readLine();
//***********

A file containing two tab-separated columns. The first strange thing
is the output I get when using readLine():
■8 - 2 0 - 2 9 . 2 6 4 9 - 4 6 - 0 2 . 0 5
8 - 2 0 - 2 8 . 1 9 4 9 - 4 5 - 5 5 . 5 2
8 - 2 0 - 3 0 . 4 6 4 9 - 4 6 - 0 5 . 1 5

First of all I get spaces all over the place and moreover it adds
character of numeric value -1 at index 1. Here replaced with "■"

Has anyone an idea where that coulb be coming from?

Thank you and have a nice day...
 
D

David Zimmerman

rkr said:
Dear all
I have a strange problem when using BufferedReaders.
I want to read the following file:
8-20-29.26 49-46-02.05
8-20-28.19 49-45-55.52
8-20-30.46 49-46-05.15
...

//***code****
BufferedReader bReader = new BufferedReader(new FileReader(filename));
String line = bReader.readLine();
//***********

A file containing two tab-separated columns. The first strange thing
is the output I get when using readLine():
■8 - 2 0 - 2 9 . 2 6 4 9 - 4 6 - 0 2 . 0 5
8 - 2 0 - 2 8 . 1 9 4 9 - 4 5 - 5 5 . 5 2
8 - 2 0 - 3 0 . 4 6 4 9 - 4 6 - 0 5 . 1 5

First of all I get spaces all over the place and moreover it adds
character of numeric value -1 at index 1. Here replaced with "■"

Has anyone an idea where that coulb be coming from?

Thank you and have a nice day...

How do you display the data? Realize that java characters are 16t bits
(two bytes) long.
 
H

hiwa

Dear all
I have a strange problem when using BufferedReaders.
I want to read the following file:
8-20-29.26 49-46-02.05
8-20-28.19 49-45-55.52
8-20-30.46 49-46-05.15
...

//***code****
BufferedReader bReader = new BufferedReader(new FileReader(filename));
String line = bReader.readLine();
//***********

A file containing two tab-separated columns. The first strange thing
is the output I get when using readLine():
■8 - 2 0 - 2 9 . 2 6 4 9 - 4 6 - 0 2 . 0 5
8 - 2 0 - 2 8 . 1 9 4 9 - 4 5 - 5 5 . 5 2
8 - 2 0 - 3 0 . 4 6 4 9 - 4 6 - 0 5 . 1 5

First of all I get spaces all over the place and moreover it adds
character of numeric value -1 at index 1. Here replaced with "■"

Has anyone an idea where that coulb be coming from?

Thank you and have a nice day...

Your output method has bug or bugs. Show the code.
 
T

Thomas Weidenfeller

rkr said:
A file containing two tab-separated columns. The first strange thing
is the output I get when using readLine():
■8 - 2 0 - 2 9 . 2 6 4 9 - 4 6 - 0 2 . 0 5
8 - 2 0 - 2 8 . 1 9 4 9 - 4 5 - 5 5 . 5 2
8 - 2 0 - 3 0 . 4 6 4 9 - 4 6 - 0 5 . 1 5

First of all I get spaces all over the place and moreover it adds
character of numeric value -1 at index 1. Here replaced with "■"

Has anyone an idea where that coulb be coming from?

You either read a non ASCII (most likely Unicode) encoded file with the
wrong file encoding, or you do the opposite: printing out the data with
the wrong encoding.

/Thomas
 
R

rkr

I want to read the following file:
BufferedReader bReader = new BufferedReader(new FileReader(filename));
String line;
while(true) {
line = bReader.readLine();
if(line==null) return;
if(line.length==1) continue;
System.out.println(line);
StringTokenizer strTok = new StringTokenizer(line);
String lon = strTok.nextToken();
String lat = strTok.nextToken();
}
Your output method has bug or bugs. Show the code.

Code added above. My output method is a simple System.out.println(String) call...
 
R

rkr

Never mind!
I got a text file that was copied out of an excel sheet. so the
strange elements result from excel... now I just have to find a way to
get the data properly!

Thanx anyway...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top