使用 Scanner 时发生 Java 错误,“没有为 Scanner 找到合适的构造函数”
我正在使用 Scanner 和 BufferedReader 对象从 url 读取文本输入,并收到此编译时错误:没有为 Scanner 找到合适的构造函数。
任何建议将不胜感激,这是代码:
import java.util.Scanner;
import java.net.*;
import java.io.*;
import java.util.Arrays;
import java.lang.*;
public class Processor
{
public void start(){
readInput();
sort();
writeOutput();
}
public void readInput()
{
Scanner scan = new Scanner();
URL file = new URL("http://file.txt");
BufferedReader reader=new BufferedReader(new InputStreamReader(file.openStream()));
Customer[] customerList = new Customer[40000];
scan.nextLine();
I am using Scanner and BufferedReader objects to read text input from a url, and am getting this compile time error: no suitable constructor found for Scanner.
any suggestions would be appreciated, here is the code:
import java.util.Scanner;
import java.net.*;
import java.io.*;
import java.util.Arrays;
import java.lang.*;
public class Processor
{
public void start(){
readInput();
sort();
writeOutput();
}
public void readInput()
{
Scanner scan = new Scanner();
URL file = new URL("http://file.txt");
BufferedReader reader=new BufferedReader(new InputStreamReader(file.openStream()));
Customer[] customerList = new Customer[40000];
scan.nextLine();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Scanner 类没有默认构造函数,
请参阅此文档
http://docs.oracle.com/javase /1.5.0/docs/api/java/util/Scanner.html
例如,此代码允许用户从 System.in 读取数字:
Scanner class doesnt have a default constructor,
See this doc
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html
For example, this code allows a user to read a number from System.in:
扫描器在其构造函数中需要一个参数。通常是一个文件或某种形式的输入流。否则 scan.nextLine() 如何知道它正在扫描什么?
Scanner requires a parameter in its constructor. A File or some form of InputStream usually. Otherwise how does scan.nextLine() know what it's scanning?
这些构造函数中,哪个接受0 个参数?
Of these constructors, which one accepts 0 arguments?