【发布时间】:2014-10-30 03:33:07
【问题描述】:
我正在尝试读取文件并打印出每一行的子字符串。我无法弄清楚我的错误是什么。我的链接有效,那么是什么导致了错误?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class FileReader {
public void fileReader() {
File file = newFile("https://www.cs.uoregon.edu/Classes/14F/cis212/assignments/phonebook.txt");
try{
Scanner scan = new Scanner(file);
while(scan.hasNextLine())
{
String numAndName = scan.nextLine();
String newNum = numAndName.substring(0, 8);
System.out.println(newNum);
}
scan.close();
} catch(FileNotFoundException e)
{
e.printStackTrace();
}
}
}
【问题讨论】:
标签: java java.util.scanner filereader filenotfoundexception