Simply - is there an easy way of determine the length of the character-stream that is coming from a textfile?
The program opens a certain text-file and then reads the characters from an object that extends FilterReader. The callback function that reads characters is the following
class: MyFilterReader
@Override
public int read(char cbuf[], int off, int len) throws IOException {
int i = in.read(cbuf, off, len);
return i;
}
And the other class that uses this object
class: Gui
InputStreamReader iSR = new InputStreamReader(System.in);
FileReader fr = new FileReader(file);
MyFilterReader mFR = new MyFilterReader(fr);
BufferedReader input = new BufferedReader(mFR);
char[] ch = new char[15000];
input.read(ch);
input.close();
for (int i = 0; i < ch.length; i++) {
if (ch[i] != 0) {
System.out.print(ch[i]);
}
}
In summary: I have no problems to read the characterstream, but I dont know how I in advance can determine its length so I can allocate that space to ch-vector (ch). As you see here I have temporarily set the size to an ad-hoc value of 15000: