Я хочу выполнить чтение из текстового файла, если я найду определенное электронное письмо, я хочу удалить всю строку.
Вот и хочу удалить [email protected]
[email protected]
otherrandomwordsinrandomorder
reandom word and spaces maybe @ and charcters [email protected]
APPLEPEARAPPLE
CATDOGCAT
[email protected]
К этому
otherrandomwordsinrandomorder
APPLEPEARAPPLE
CATDOGCAT
Код:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
class SendReq {
public static void main(String[] args) throws FileNotFoundException,
IOException{
File inputFile = new File("testfile.txt");
if (!inputFile.exists()){
inputFile.createNewFile();
}
File tempFile = new File("tempfile.txt");
if (!tempFile.exists()){
tempFile.createNewFile();
}
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
String lineToRemove = "[email protected]";
String currentLine;
while((currentLine = reader.readLine()) != null) {
// trim newline when comparing with lineToRemove
String trimmedLine = currentLine.trim();
if (trimmedLine.equals(lineToRemove)) continue;
writer.write(currentLine + System.getProperty("line.separator"));
}
writer.close();
reader.close();
boolean successful = tempFile.renameTo(inputFile);
System.out.println(successful);
}
}
О, БОГ, он взял все мои строки и смешал их вместе, извините, это мой первый пост.
Если (trimmedLine.contains (lineToRemove)) продолжить; ?




А ваш вопрос?