It's not a secret anymore!*
The moose likes I/O and Streams and the fly likes BufferedReader skill problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "BufferedReader skill problem" Watch "BufferedReader skill problem" New topic
Author

BufferedReader skill problem

Hugo Leung
Greenhorn

Joined: Feb 27, 2007
Posts: 7
Dear all,

I would like to know how to read the white space on the BufferedReader function. For example , i have the abc.txt file the format is :

1 0 0 1 0 1 0
0 1 0 0 0 0 0



But i only can read this format:

1001010
0100000


Some of the below program :

....
...
....
public void aCreate(String file)
{
String inStr ="";
int i =0 , j =0 , index =0;;
int sizeOfa;
try
{
BufferedReader ioReader = new BufferedReader(new FileReader(file));
sizeOfa=Integer.parseInt(ioReader.readLine());
a = new int[sizeOfa][sizeOfa];
while ((inStr = ioReader.readLine())!= null)
{
for (j =0; j < inStr.length();j++)
{
System.out.print((a[i][j] = Integer.parseInt(new Character(inStr.charAt(j)).toString())));
}
i = i +1;
System.out.print("\n");
}
}
catch(Exception e)
{
e.printStackTrace();
}


....
...
....
System.out.println("The Path is:");
}


In fact, i would to read have white space txt file . thanks you
Kamal Joshi
Greenhorn

Joined: Jan 30, 2006
Posts: 9
Didn't get your code actually. But anyways if you just want to read each character
every invocation of readline() returns a String object.( which consists of all the spaces in the line )

From this String either you can retrieve a char array (inStr.toCharArray()) then happily index any character
or retrieve each character directly using (inStr.charAt(index))


/*sample code*/

public void aCreate(String file) {
String inStr = "";

try {
BufferedReader ioReader = new BufferedReader(new FileReader(file));
while ((inStr = ioReader.readLine()) != null) {
for(int x=0;x<inStr.length();x++){
System.out.print(inStr.charAt(x));
}
System.out.println();
}
} catch (Exception e) {
e.printStackTrace();
}


}
 
GeeCON Prague 2014
 
subject: BufferedReader skill problem