Trouble writing an Integer to a text file and reading back with scanner and storing
What I have been trying to do is write an int to a file. Seems easy enough, but there is a catch like everything in life. I have to append it to the eof. Now I have tried RandomAccessFile, Formatter, FileWriter etc... c nothing I seem to do works. I have to be able to write an int because it stores the user value and I need to be able to manipulate it in the future. The scanner class seems to be only good for Strings, so I thought read it in as a String and convert using the parase method. I have been struggling with this problem for quite sometime. I am almost finished with the program and hit this wall. I am new to Java, so I don't know how to really work through this problem. Every time I have had an idea it has been a fail. Here is a small program I was trying to do:
Can someone please give me something of substance to work with. I really need to know how to write int in binary, and able to store it in a variable so I can manipulate with my program. It has to be at the end of the file or a new line, and RandomAccessFile has seek method, which makes this ideal class to use. Is there a way to write an Int using RandomAccessFile or FileWriter as an int and use something like scanner class or another class to read that binary code and store it as a variable as an int. Thank you in advance.
File f = new File("C:\\Test\\kkk.txt");
FileWriter wf = new FileWriter(f,true);
Scanner sr = null;
sr = new Scanner(f);
String a = "";
a = sr.next();
int b = Integer.parseInt(a);
Re: Trouble writing an Integer to a text file and reading back with scanner and stori
I really could use some help.