【发布时间】:2014-03-03 17:46:07
【问题描述】:
//我正在尝试获取这个文件并根据最后的######### 分离卡片 //我正在用java制作一个robocop风格的纸牌游戏来玩,我制作了纯文本文件中的卡片,我希望能够读取文件并将文件分成卡片。最终,我希望能够调用这些卡片并在需要时将它们打印出来。
试试{
File file = new File("MyText.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = null;
while((line = reader.readLine()) != null){
addCard(line);
}
}catch(Exception ex){
ex.printStackTrace();
}
//Problem! This only prints the first card?!? HELP!
for(i = 0; i < playerList.size(); i++){
System.out.println(playerList.get(i));
}
}
void addCard(String lineToParse){
String[] tokens = lineToParse.split("##########");
// How do I increment the token to the next token and add to playerList?
playerList.add(tokens[0]);
}
}
【问题讨论】:
-
什么是
j,为什么需要j==0? -
这是我尝试增加令牌并转到下一个令牌以添加到 playerList
-
为什么投反对票?你们不要乱用代码,看看什么有效/无效吗? ...
标签: java split token bufferedreader