首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >数字格式异常,真的卡住了

数字格式异常,真的卡住了
EN

Stack Overflow用户
提问于 2013-11-24 06:11:39
回答 1查看 126关注 0票数 0

这是我的代码..。我正在弄一个NumberFormatException,我想知道怎么解决这个问题。新手,完全卡住了,真的需要帮助

代码语言:javascript
运行
复制
public class AcccountArray {

    public static void main(String[] args) 
    {
        //Scan the file and save account details to array
        File file = new File ("customers.txt");
        System.out.println("Path : " + file.getAbsolutePath());
        try{
                    Scanner scanner = new Scanner("customers.txt");
                    String[][] Account = new String[Integer.valueOf(scanner.nextLine())][3];

                    for(int i=0;i<Account.length;i++)
                    {
                        Account[i][0]=scanner.nextLine();
                        //System.out.println(Account[i][0]);
                        Account[i][1]=scanner.nextLine();
                        //System.out.println(Account[i][1]);
                        Account[i][2]=scanner.nextLine();
                        //System.out.println(Account[i][2]);
                    }
                    scanner.close();

错误:

代码语言:javascript
运行
复制
java.lang.NumberFormatException: For input string: "customers.txt"
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.valueOf(Unknown Source)
    at AcccountArray.main(AcccountArray.java:15)

李。15是

代码语言:javascript
运行
复制
String[][] Account = new String[Integer.valueOf(scanner.nextLine())][3];
EN

回答 1

Stack Overflow用户

发布于 2013-11-24 06:12:35

使用接受FileScanner的构造函数,以便扫描仪实例不使用String源:

代码语言:javascript
运行
复制
Scanner scanner = new Scanner(new File("customers.txt"));

因为您已经有了这个引用,所以可以使用

代码语言:javascript
运行
复制
Scanner scanner = new Scanner(file);
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20168525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档