这是我的代码..。我正在弄一个NumberFormatException,我想知道怎么解决这个问题。新手,完全卡住了,真的需要帮助
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();错误:
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是
String[][] Account = new String[Integer.valueOf(scanner.nextLine())][3];发布于 2013-11-24 06:12:35
使用接受File的Scanner的构造函数,以便扫描仪实例不使用String源:
Scanner scanner = new Scanner(new File("customers.txt"));因为您已经有了这个引用,所以可以使用
Scanner scanner = new Scanner(file);https://stackoverflow.com/questions/20168525
复制相似问题