1
我不确定为什么这段代码不会让我选择一个文件然后扫描它。任何帮助表示赞赏。谢谢。为什么不能导入文件?
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;
}
你有什么麻烦?你是否遇到错误,而不是你期望的结果,或者其他什么? – 2010-11-13 06:12:28
我正在收到“文件未找到”异常。 – 2010-11-13 13:52:14