Hi,
I have a rather large binary file that I am attempting to read in, but I only want to read in the first 100 characters or so. I've tried searching the internet for help or an example, but I've only found examples that read in the entire file...and this file is too big to be read in all at once. I tried to split it up by the '\n' character, but it is apparently a continuous string of binary characters. Here is what I have so far - can anyone point me in the right direction? Thank you!
try {
int c;
String readInfo = "";
File myFile = new File("test.txt");
FileReader in = new FileReader(myFile);
while ((c = in.read()) != -1) {
readInfo = readInfo + (char)c;
}
in.close();
pirateInfo = readInfo.split("\n");
if (pirateInfo[1] == null){
pirateInfo[1].equals("");
}
for (int i = 0; i < 100; i++){
System.out.println(pirateInfo[i]);
}
}
catch (IOException ioe){
JOptionPane.showMessageDialog(null, "The file 'test.txt' was not found.");
}
Again, thank you for any assistance!