我正在尝试拆分从文件中读取的文本,当我这样做时,它将整行作为数组元素,我做错了还是只是拆分不是我需要使用的。
public void readBoard(String file)throws FileNotFoundException
{
File clboard = new File ("myBoard.csv");
Scanner x = new Scanner(clboard);
while(x.hasNext())
{
String c = x.nextLine();
String [] myboard =c.split(",,");
int p1= Integer.parseInt(myboard[1]);
int p2= Integer.parseInt(myboard[2]);
if(myboard[0].equals("Chute"))
{
board[p1][p2]= new Chute();
}
else
{
board[p1][p2]= new Ladder();
}
}
}
这是我正在阅读的文件
29
Chute,1,0
Chute,2,0
Chute,3,0
Chute,4,0
Chute,5,0
Chute,6,0
Chute,7,0
Chute,8,0
Chute,9,0
Chute,0,1
Chute,0,2
Chute,0,3
Chute,9,1
Chute,9,2
Chute,9,3
Ladder,0,5
Ladder,1,5
Ladder,2,5
Ladder,3,5
Ladder,4,5
Ladder,5,5
Ladder,6,5
Ladder,7,5
Ladder,8,5
Ladder,9,5
Ladder,9,6
Ladder,9,7
Ladder,9,8
Ladder,9,9