Question: Using what is already shown in the Java code, I need to check whether the first number of each row in File.txt duplicates or not.

Using what is already shown in the Java code, I need to check whether the first number of each row in File.txt duplicates or not. What I mean by this is as follows:
1,2,3
1,5,6
2,1,5
The first numbers of each row are 1 1 and 2. Since the first number of row one and two duplicate, I need to replace all of row 2 with a string: "Duplicate entry on line 2" and would also need to do so if there were any additional duplicates if the file continued. How can I add to my existing code to make that happen?
Notice that the code skips the first line and continues to display starting from line 2. This is intentional so you can read the example above as starting from line 2 and going to line 4.
import java.io. BufferedReader; //import java.io. Bufferedwriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Voter { public static void main(String[] args) { BufferedReader bf = null; 1/BufferedWriter bw = null; try { FileReader fr = new FileReader("File.csv"); //FileWriter fw = new FileWriter("File.csv); bf = new BufferedReader(fr); bf.readLine(); String line; while((line = bf.readLine()) != null){ System.out.println(line); } } catch (FileNotFoundException e) { e.printStackTrace(); System.err.println("File not found"); } catch (IOException e) { System.err.println("Cannot read the file"); } finally { try { bf.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } import java.io. BufferedReader; //import java.io. Bufferedwriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Voter { public static void main(String[] args) { BufferedReader bf = null; 1/BufferedWriter bw = null; try { FileReader fr = new FileReader("File.csv"); //FileWriter fw = new FileWriter("File.csv); bf = new BufferedReader(fr); bf.readLine(); String line; while((line = bf.readLine()) != null){ System.out.println(line); } } catch (FileNotFoundException e) { e.printStackTrace(); System.err.println("File not found"); } catch (IOException e) { System.err.println("Cannot read the file"); } finally { try { bf.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
