inputFileName = "2.txt";
   outputFileName = "3.txt";
   inputFile = new BufferedReader(new FileReader(inputFileName));
   outputFile = new PrintWriter(new FileWriter(outputFileName));
   String lineOfText = inputFile.readLine();
   while (lineOfText != null)
   {
       if (lineOfText.contains("x"))
       {
           lineOfText = lineOfText.replaceAll("x"+ ".*", "");
       } 
       outputFile.println(lineOfText);
       lineOfText = inputFile.readLine();
   } 
   inputFile.close();
   outputFile.close();
Hello, right now I have an input and output, does that mean I have two try and two catch blocks (there might be an error connecting to the previous file and writing to the second file). Or would I need only one try block?
If so, how/where would I implement the try and catch blocks?
 
                        
I would only use one try/catch/finally-block by writing:
By using the
finallyblock you can be sure that theReaderandWriterobject are definitely closed.