C
cyclone771
Hi. I have recently started learning to program using Java, and I am
currently working on creating a counter. Right now I am working as an
application only, and would like to know how to get my program to open
a file (Already done, I think.) and get it to save the contents as an
integer, x. Any help would be greatly appreciated. Here is the source
code:
import java.io.*;
class counter {
public static void main(String[] args) throws IOException {
File inputFile = new File("counter.jvar");
File outputFile = new File("counter.jvar");
FileReader in = new FileReader(inputFile);
int x = in;
/* I know this(^^) line creates an error b/c of diff file types, but
how do I fix it? */
in.close();
int y = (x + 1);
System.out.println(y);
FileWriter out = new FileWriter(outputFile);
out.write(y);
out.close();
}
}
currently working on creating a counter. Right now I am working as an
application only, and would like to know how to get my program to open
a file (Already done, I think.) and get it to save the contents as an
integer, x. Any help would be greatly appreciated. Here is the source
code:
import java.io.*;
class counter {
public static void main(String[] args) throws IOException {
File inputFile = new File("counter.jvar");
File outputFile = new File("counter.jvar");
FileReader in = new FileReader(inputFile);
int x = in;
/* I know this(^^) line creates an error b/c of diff file types, but
how do I fix it? */
in.close();
int y = (x + 1);
System.out.println(y);
FileWriter out = new FileWriter(outputFile);
out.write(y);
out.close();
}
}