private static boolean modifyFileContent(String filePath, String replaceContent, String regex) {
//修改文件内容,写入日期
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(filePath, "rw");
String line = null;
long lastPoint = 0; //记住上一次的偏移量
while ((line = raf.readLine()) != null) {
final String str = replaceFileContent(line, replaceContent, regex); //读取文件一行,将匹配正则的字符串替换。
final long ponit = raf.getFilePointer();
raf.seek(lastPoint);
raf.writeBytes(str);
lastPoint = ponit; //读取一行,指针指到下一行开头。用作写下一行,偏移量的开始,。
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e
//修改文件内容,写入日期
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(filePath, "rw");
String line = null;
long lastPoint = 0; //记住上一次的偏移量
while ((line = raf.readLine()) != null) {
final String str = replaceFileContent(line, replaceContent, regex); //读取文件一行,将匹配正则的字符串替换。
final long ponit = raf.getFilePointer();
raf.seek(lastPoint);
raf.writeBytes(str);
lastPoint = ponit; //读取一行,指针指到下一行开头。用作写下一行,偏移量的开始,。
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e