Hello, I've been trying to read txt from a file, and breaking each line into words and storing them in Array.
Example. txt file
C001 John Smith 999999
C002 Mary Agnes 888888
Here is my code.
public class Customer implements iCommand{
static List<Customer> cust = new ArrayList<Customer>();
static private String cID, String cName, cPhonenum;
public Customer(String id, String name, String phone_num){
this.cID = id;
this.cName = name;
this.cPhonenum = phone_num;
}
public static void main(String[] args){
Scanner f = null;
try {
f = new Scanner(new File("C:/x.txt"));
} catch (FileNotFoundException e) {
System.out.println("unable to open file");
e.printStackTrace();
}
while (f.hasNextLine()){
String input = null;
String[] words = input.split("");
Customer client = new Server( cID, cName, cPhonenum);
clients.add(client);
}
}
}
Can anyone help me because I haven't found what I'm looking for with my current code.
Thanks.