|
I need to update a players Information. I am able to change the players information by the following method:
public String updatePlayerInfo(int playerNr,int correct,int gamesPlayed)throws FileNotFoundException,IOException
{
String playerInfo="";
FileReader fr=new FileReader(myFile);
BufferedReader br=new BufferedReader(fr);
String line=br.readLine();
while(line!=null)
{
StringTokenizer st=new StringTokenizer(line);
String num=st.nextToken();
int playerNum=Integer.parseInt(num);
String name=st.nextToken();
String score=st.nextToken();
int correctGames=Integer.parseInt(score);
String play=st.nextToken();
int played=Integer.parseInt(play);
if(playerNum==playerNr)
{
correctGames=correct;
played=gamesPlayed;
playerInfo=playerInfo+playerNum+" "+name+" "+correctGames+" "+played;
playerInfo=playerInfo+"\n";
}
line=br.readLine();
}
return playerInfo;
}
I am having trouble updating the text file with the new information
|