将数据写入文件
public static void writeFile(String fileName, byte[] bytes) {
try {
File file = new File(fileName);
RandomAccessFile rf = new RandomAccessFile(file, "rw");
long len = rf.length();
rf.seek(len);
rf.write(bytes, 0, bytes.length);
rf.close();
} catch (Exception e) {
};
}
将数据从文件中读出到byte数组
public static byte[] readFile(String fileName, int index, int len) {
try {
byte[] bytes = new byte[len];
File file = new File(fileName);
RandomAccessFile rf = new RandomAccessFile(file, "rw");
rf.seek(index);
rf.read(bytes, 0, len);
rf.close();
return bytes;
} catch (Exception e) {
};
return null;
}