Hi,
I'm trying to save an integer called speed in a text file in order to read it afterwards. Therefore I've tried to use the following code:
public void writefile()
{
FileWriter out = null;
try
{
out = new FileWriter("data.txt");
BufferedWriter writer = new BufferedWriter(out);
writer.write(speed);
}
catch (IOException e){ e.printStackTrace(); }
finally
{
if(out != null)
{
try {out.close();}
catch (IOException e) {e.printStackTrace();}
}
}
}
public void readfile()
{
String line = null;
int value=0;
FileReader file = null;
try
{
file = new FileReader("data.txt");
BufferedReader reader = new BufferedReader(file);
while((line = reader.readLine()) != null)
{
value = Integer.parseInt(line);
}
}
catch (FileNotFoundException e) {throw new RuntimeException("Error");}
catch (IOException e) {throw new RuntimeException("Error");}
finally
{
if(file != null)
try {file.close();}
catch (IOException e) {e.printStackTrace();}
}
speed=value;
}
What happens is that at the end speed is 0,instead of what it should be.
I'd be grateful for some help :)

