Reputation: 27
I'm trying to rename the file that my program is outputting, but no matter what name i'm trying to change it to, it is stuck with the first name i listed which is "output.txt". I rename it to output1. txt and it still gives me output.txt could someone help with this?
public class Assignment2 {
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Sample command: java Assignment2 input.txt");
System.exit(0);
}
try {
Scanner scanner = new Scanner(new File(args[0]));
FileWriter fw = new FileWriter("output1.txt");
int i = 1;
while (scanner.hasNext()) {
System.out.println("Matrix #" + i);
processMatrix(scanner, fw);
i++;
System.out.println("");
fw.write(System.lineSeparator());
}
scanner.close();
fw.close();
} catch (FileNotFoundException ex) {
System.out.println(ex.getMessage());
} catch (IOException ex) {
Logger.getLogger(Assignment2.class.getName()).log(Level.SEVERE, null, ex);
}
}
Upvotes: 1
Views: 93
Reputation: 26
From what I can see there is nothing wrong with your code.
So the only problem I can think of, is you are not building/compiling the file and therefore you are stuck on a older version of that file.
I don't know what technology stack you are using, but a still way to check this since its java, hopefully you got the environment variables configures. Just go to your terminal, to the file folder and:
javac Assignment2.java java Assignment2
You can also tell me which IDE you are using, or how you are building/running your code.
Upvotes: 1