我正在尝试读取/扫描此文件,并将行拆分为单独的变量,但无法看到任何输出。无论如何要检查这个吗?
来自档案的样本行:
史密斯,约翰,123-789-4560,生日1/1/2000
Picasso,Pablo,123-654-0987,House Painter
public final void readFile() throws IOException
{
try (Scanner scan = new Scanner(new File("C://ContactList/ContactList.txt")))
{
while(scan.hasNext())
{
String currentLine = scan.nextLine();
String[] splitString = currentLine.split(",");
importNameLast = splitString[0].trim();
importNameFirst = splitString[1].trim();
importPhoneNumber = splitString[2].trim();
importContactNotes = splitString[3].trim();
}
}
}
private void populateContactList()
{
System.out.println("Initializing Contacts");
contactList = new ArrayList<>();
contactList.add(new Contact("Doe", "John", "123-456-7890", "null"));
contactList.add(new Contact("Doe", "Jane", "123-456-7890", "null"));
contactList.add(new Contact(importNameLast, importNameFirst, importPhoneNumber, importContactNotes));
}