正在扫描但未存储在变量中的文本文件

时间:2015-09-21 15:25:04

标签: java file-io java.util.scanner

我正在尝试读取/扫描此文件,并将行拆分为单独的变量,但无法看到任何输出。无论如何要检查这个吗?

来自档案的样本行:

史密斯,约翰,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));

}

0 个答案:

没有答案