1

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);
    }

}
4
  • 3
    I suspect you've made a mistake in your testing. new FileWriter("output1.txt") will not create a file called "output.txt". Commented Nov 29, 2018 at 18:10
  • i'm trying to get it to output to output1.txt but it still output a file name output.txt Commented Nov 29, 2018 at 18:12
  • 2
    You probably have a compile error or something in your code that results in stale code to be executed. Also make sure to re-compile your code after making changes. Java is no scripting language and you need to compile your code after each change to take effect. Commented Nov 29, 2018 at 18:23
  • 1
    When I run your code, it creates output1.txt as expected. How, exactly, are you running your code, and how are you making sure it's creating the wrong file? Commented Nov 29, 2018 at 18:23

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

i'm using Eclipse. so where should i go to clear out the system so that i can get my code to run again?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.