您的位置:首页 > 移动开发 > Android开发

android向文件指定位置写数据

2011-05-05 09:59 561 查看
/**
*
* 向文件指定位置写数据
*
* @param skipBytes
* 指定位置
* @author zhoobt
*
*/
public static boolean writeData(File file, long skipBytes, byte[] data) {
boolean result = false;
try {
RandomAccessFile rFile;
if (file.exists()) {
rFile = new RandomAccessFile(file, "rw");
rFile.seek(skipBytes);
byte[] otherdata = new byte[(int) (file.length() - skipBytes)];
rFile.read(otherdata);
rFile = new RandomAccessFile(file, "rw");
rFile.seek(skipBytes);
rFile.write(data);
rFile = new RandomAccessFile(file, "rw");
rFile.seek(data.length + skipBytes);
rFile.write(otherdata);
rFile.close();
rFile = null;
result = true;
}
} catch (Exception e) {
}
return result;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: