public void removeLine() {
try {
File dir = new File("chars");
if(dir.exists()) {
String read;
File files[] = dir.listFiles();
for (int j = 0; j < files.length; j++) {
File loaded = files[j];
if (loaded.getName().endsWith(".txt")) {
Scanner s = new Scanner (loaded);
while (s.hasNextLine()) {
read = s.nextLine();
if (read.contains("char-15")) {
read.replace(read, "");
System.out.println(loaded.getName() +" - Data: "+read);
break;
}
}
}
}
}
} catch (Exception e) {
}
}
これが行うべきことは、「char-15」を含む各行を空の文字列に置き換えることです。
ただし、これを実行すると、すべてのファイルの行が削除されません。5000をはるかに超えるファイルがあるため、これを手動で行うことはできません。
すべてのファイルでこの特定の行を削除するにはどうすればよいですか?