简体   繁体   English

从文件中读取会导致 java.util.InputMismatchException

[英]Reading from a file causes java.util.InputMismatchException

I seem to be getting java.util.InputMismatchException when reading from a file.从文件读取时,我似乎收到 java.util.InputMismatchException 。 The file is just an array of numbers该文件只是一个数字数组

Please advise.请指教。

package assignment1;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Question4 {

public static void main(String[] args) throws FileNotFoundException 
{

    Scanner inFile = 
              new Scanner(new FileReader("glassdatatxt.txt"));

    Double [][] glassdata = new Double[214][11];

    for(int row = 0; row < glassdata.length; row++)
    {
        for(int col = 1; col < glassdata[row].length; col++)
        {
           glassdata[row][col] = inFile.nextDouble();
        }
    }


    for(int row = 0; row < glassdata.length; row++)
    {
        for(int col = 1; col < glassdata[row].length; col++)
        {
            System.out.print(glassdata[row][col] + " ");
        }
        System.out.println();
    }

}

}

It was not reading the space character correctly.它没有正确读取空格字符。 Initially I have commas in between the numbers.最初我在数字之间有逗号。 I replace the commas incorrectly.我错误地替换了逗号。 I got it to work now.我现在开始工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM