I am trying to figure out how to remove all commas from a text file so that I can output it in the console where there are no commas. My input.replace("[,]", "");
statement isn't working and I don't know how to fix it.
I'd appreciate the help.
Text file:
75 Fresco, Al
67 Dwyer, Barb
55 Turner, Paige
108 Peace, Warren
46 Richman, Mary A.
37 Ware, Crystal
83 Carr, Dusty
15 Sledd, Bob
64 Sutton, Oliver
70 Mellow, Marsha
29 Case, Justin
35 Time, Justin
8 Shorts, Jim
20 Morris, Hugh
25 Vader, Ella
76 Bird, Earl E.
My code:
import java.io.*;
import java.util.*;
public class Ex2 {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("people.txt"));
while (input.hasNext()) { // Input == people.txt
String line = input.nextLine();
input.replace("[,]", "");
System.out.println(line);
}
}
}