I am trying to make a scoring system for a game I'm writing, but I need to be able to read an integer variable from a text document. I can easily get a String variable, but it won't come in as an integer. How would I go about doing that? Here is the code I have for reading and writing the score, but the input won't come in as an integer, as you can see when the println outputs the value of score2 integer. Thanks! I'm using an eclipse IDE for Java by the way.
import java.io.*;
public class ClassName {
public static void main(String[] args) {
FileOutputStream output;
FileInputStream input;
in score = 10;
int integer = 4;
try {
output = new FileOutputStream("score.txt");
new PrintStream(output).println(score);
output.close();
} catch (IOException e) {}
try {
input = new FileInputStream ("score.txt");
int score2 = (new DataInputStream(score).readLine());
input.close();
System.out.println(score2);
} catch (IOException e) {}
}
}
}