怎么把txt文件读取到java 二维数组中

hello. 下面这个是我的txt文件,我想把除了第一行的数字12以外,下面的这组数据放到二维数组LES(x,y)中,请问使用java如何实现

12
000001000000
000000010010
000000000000
000100000010
000000000001
000010000000
100000000000
000000001000
000000000000
011000000000
011000100000
000000000000

这样假如说LES(12,12)就是最后一个数, =0.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Test6
{
public static int[][] save(String fileName)
{
int[][] les = null;
try
{
Scanner scanner = new Scanner(new File(fileName));
int i = 0;
while(scanner.hasNextLine())
{
String line = scanner.nextLine().trim();
if(i == 0)
{
int num = Integer.parseInt(line);
les = new int[num][num];
}
else
{
for(int j = 0; j < line.length(); j++)
{
les[i - 1][j] = Integer.parseInt(line.charAt(j) + "");
}
}
i++;
}
scanner.close();
return les;
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
return null;
}

public static void main(String[] args)
{
int[][] LES = save("les.txt");
System.out.println(Arrays.deepToString(LES));
}
}

温馨提示:答案为网友推荐,仅供参考