0
// Create file
FileWriter fstream = new FileWriter(fileName, true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(c.toString());
//Close the output stream
out.close();
// Code I used to read record I am using | as a seperator name and id
String fileName = folderPath + "listCatalogue.txt";
String line = "";
Scanner scanner;
String name, id;
scanner = new Scanner(fileName);
System.out.println(scanner.hasNextLine());
while (scanner.hasNextLine()) {
line = scanner.nextLine();
System.out.println(line);
StringTokenizer st = new StringTokenizer(line, "|");
name = st.nextToken();
id = st.nextToken();
catalogues.add(new Catalogue(name, id));
}
上面是創建文件和讀取文件的代碼,我怎樣才能刪除某些記錄,在File中,我從google找到的是刪除文件但不刪除某些文件記錄示例我提供名稱,如果匹配刪除此記錄。以及修改該記錄?是否有可能使用File做修改記錄?Java刪除或修改文件中的一個記錄