我如何逐个阅读数字?

use*_*742 2 java

我尝试用扫描仪读取文件中的数字.但我不能一一阅读.我怎样才能做到这一点?

这是我的txt

000000000000000000000000000000000000000
Run Code Online (Sandbox Code Playgroud)

这是我的代码

ArrayList<Integer>x = new ArrayList<>();

    Scanner scan;

    try {
        scan = new Scanner(new FileInputStream(new File("d:/deneme.txt")));
        while(scan.hasNext()){
            int y = scan.nextInt();
            System.out.println(y);
            x.add(y);               
        }
        scan.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

Ada*_*ost 6

当您读入nextInt时,它会将000000000000000000000视为0.如果您使用String y = scan.next(),则通过检y.charAt(i) 入for循环进行解析, 您将检查数字字符串的每个位置中的数字.

然后必须解析该char,并将其存储为int,因此请使用

int x = Character.getNumericValue(y.charAt(i));