I'm trying to update a value in a text file. In my text file I have the value 100 which I'm trying to add 1 too. Whenever I run the code though, it doesn't print anything or write into the text file.
public static void main(String[] args) throws IOException {
try {
File myObj = new File("C:\\Users\\proto\\OneDrive\\Documents\\atmDep.txt");
Scanner myReader = new Scanner(myObj);
FileWriter myWriter = new FileWriter("C:\\Users\\proto\\OneDrive\\Documents\\atmDep.txt");
while (myReader.hasNextLine()) {
int data = myReader.nextInt();
int num = 1;
myWriter.write(data + num);
System.out.println(data);
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}