您将获得一个文本文件,其中包含3x3网格形式的字符。我想知道如何以相同顺序将其存储到2D阵列中。与[x] [y]类似,因此您可以轻松访问该字母。因此,在下面的代码中,执行array [1] [2]会给您“ H”,因为它的1向上和2向下?
此方法称为load(Path path),基本上我所做的就是制作一个fileScanner来扫描文件,然后将每个字符存储到2D数组中。
*Pretend the text file looked like the example below not including
*these first two line
* SER
* NHO
* AIL
public void load(Path path){
File file = path.toFile();
try {
Scanner fileScanner = new Scanner(file);
} catch(FileNotFoundException e){
System.out.println("File does not exist");
}
}
*and printing out the array should look like
*SER
*NHO
*AIL