Java code for removing lines

import java.io.*; import java.util.ArrayList; import java.util.List;

public class RemoveLinesWithSpecificWord { public static void main(String[] args) { String inputFile = "input.txt"; // Replace with your input file path String outputFile = "output.txt"; // Replace with your output file path String wordToRemove = "specific-word"; // Replace with the word you want to remove

try { File file = new File(inputFile); BufferedReader br = new BufferedReader(new FileReader(file)); List lines = new ArrayList<>();

String line; while ((line = br.readLine()) != null) { if (!line.contains(wordToRemove)) { lines.add(line); } }

br.close();

BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile)); for (String updatedLine : lines) { bw.write(updatedLine); bw.newLine(); } bw.close();

System.out.println("Lines with the word '" + wordToRemove + "' removed successfully."); } catch (IOException e) { e.printStackTrace(); } } }