Sab
Sab

Reputation: 75

Unable to read whitespaces when reading from a dat file in java

I am trying to read a dat file and store column names. The first line in the file is separated by spaces. The following code is unable to split the column names from the line

FileInputStream fis=new FileInputStream("file.dat");
BufferedReader br=new BufferedReader(new InputStreamReader(fis));
String line=br.readLine();``
String k[]=line.split(" ");

if i print k[0] it prints the entire line and the same does not happen if its a text file. What should i do to read the white space

Upvotes: 1

Views: 401

Answers (1)

Joni
Joni

Reputation: 111269

It's possible that the fields are separated by whitespace other than the simple " " space. You can try splitting by any kind of whitespace with:

String k[]=line.split("\\s");

If this doesn't work either, the data is not separated by whitespace. Try using a hex editor/viewer to see what the separator character is.

Upvotes: 4

Related Questions