Search code examples
javafileformatter

Write to file with Formatter in VSCode


I've read all about Formatter and tried so many ways but my hey.txt file won't change anyway.

public class foo {
    public static void main(String[] args) {
        File file = new File("hey.txt");
        System.out.println(file.exists());
        Formatter formatter;
        try {
            formatter = new Formatter(file);
            formatter.format("%d %s", 5345, "fds59fd");
            formatter.flush();
            formatter.close();
        } catch (Exception e) {
            System.out.println("yes");
            System.exit(1);
        }

    }
}

Solution

  • Actually it's because of VSCode. I ran it from cmd and came to answer.