Reputation: 1117
i wanna read a 90kb file (which apparently equals approximately 90,000 bytes) using Java's BufferedReader, but it stops after only 61 bytes. The file's alright, I've checked it using an HexEditor.
private ArrayList<byte[]> readAsBytes(String dir, String filename, int lineCount) {
/** Read file as byte*/
ArrayList<byte[]> outputArr = new ArrayList<byte[]>();
try {
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream (dir+filename));
BufferedReader reader = new BufferedReader(inputStreamReader);
if (lineCount == -1) {
String buf = "";
buf = reader.readLine();
if (buf != null) {
outputArr.add(buf.getBytes());
}
}
else {
for (int i = 0; i < lineCount; i++) {
String buf = reader.readLine();
if (buf != null) {
outputArr.add(buf.getBytes());
}
else continue;
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Can anyone help? Probably kinda simple mistakes, but it I'm starting to get tired...
Upvotes: 0
Views: 236
Reputation: 1117
The BufferInputStream
instead BufferedReader
did the job quite well. Completely forgot that this class exists.
Upvotes: 1