Does anyone else think its stupid that there's no compiler switch to allow for single byte chars? The fact that this statement doesn't work is lame:
<pre>
File f = new File("myfile.dat");
if(f.exists())
{
FileInputStream s = new FileInputStream(f);
byte[] buffer = new byte[f.size()];
int read = -1;
int offset = 0;
while((read = s.read(buffer, offset, buffer.length - offset) != -1)
{
offset += read;
}
s.close();
String str = new String(buffer);
buffer = null;
int beginIndex = str.indexOf(myByteSignature);
int endIndex = str.indexOf(myByteSignature2, beginIndex);
str = str.substring(beginIndex, endIndex);
FileWriter fw = new FileWriter("myoutput.dat");
fw.write(str);
fw.flush();
fw.close();
}
</pre>
To do simple binary file interaction I had to create a class called "ByteString" that was backed by a byte array instead of a normal String.