如何编辑RandomAccessFile中的信息?

时间:2017-03-20 20:02:56

标签: java

我已设法在下面的文件中保存两条独立的信息。但我很想知道如何编辑此文件中的信息。

try {
    RandomAccessFile fileWriter = new RandomAccessFile("Officers.txt", "rw");

    fileWriter.seek(fileWriter.length());
    fileWriter.writeUTF(officerObject.getOfficerBadgeNum());
    fileWriter.writeUTF(officerObject.getOfficerFirstName());
    fileWriter.writeUTF(officerObject.getOfficerLastName());
    fileWriter.writeUTF(officerObject.getOfficerPrecint());

    fileWriter.close();
    System.out.println("Data Successfully Saved");
}
catch (IOException e) {
    System.out.println("Error in File. Could not SAVE Officer");
    e.printStackTrace();
}

0 个答案:

没有答案