JAVAutil。扫描器java。伊奥。FileNotFoundException,错误是什么?
我试图读取一个文件并打印出每行的子字符串。我想不出我的错误是什么。我的链接有效,那么是什么导致了错误
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();
}
}
}
# 1 楼答案
问题是文件名。这不是一个文件名,而是一个URL,它不是指一个文件,而是指一个HTTP资源。将其删除,然后更改以下内容:
为此:
E&;OE