我不确定为什么这段代码不允许我选择一个文件然后扫描它。我该如何调试它?
private String[][] importMaze(){
String fileName;
JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
fileName = fc.getSelectedFile().getName();
File f = new File(fileName);
try {
Scanner scan = new Scanner(f);
int rows = scan.nextInt();
int columns = scan.nextInt();
String [][] maze = new String[rows][columns];
int r = 0;
while(scan.hasNext() && r<=rows){
for(int c = 0; c<=columns;c++){
maze[r][c]=scan.next();
}
r++;
}
return maze;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}