我有點卡住了。我如何得到這個工作或有更好的方法?請給出代碼示例。讀取.txt文件並存儲在二維char數組中java
public char[][] charmap = new char[SomeInts.amount][SomeInts.amount];
public void loadMap() throws IOException{
BufferedReader in = new BufferedReader(new FileReader("map1.txt"));
String line = in.readLine();
while (line != null){
int y = 0;
for (int x = 0; x < line.length(); x++){
//Error
charmap[x][y] = line[x];
//
}
y++;
}
}
謝謝,它解決了錯誤,我的程序現在可以運行。不按預期工作。我會發布更詳細的內容。 –