Question: Given my code:

```
import java.util.Scanner;

public class AccountTest {

    public static void main(String[] args) {
        Account account1 = new Account(50.00);
        Account account2 = new Account(0.00);

        System.out.printf("account1 balance: $%.2f\n", account1.getBalance());
        System.out.printf("account2 balance: $%.2f\n\n", account2.getBalance());

        Scanner input = new Scanner(System.in);

        System.out.print("Enter withdrawal amount for account1: ");

        double withdrawalAmount = input.nextDouble();

        System.out.printf("\nsubtracting %.2f from account1 balance\n",
                withdrawalAmount);

        account1.debit(withdrawalAmount);

        System.out.printf("account1 balance: $%.2f\n", account1.getBalance());
        System.out.printf("account2 balance: $%.2f\n\n", account2.getBalance());

        System.out.print("Enter withdrawal amount for account2: ");
        withdrawalAmount = input.nextDouble();
        System.out.printf("\nsubtracting %.2f from account2 balance\n",
                withdrawalAmount);
        account2.debit(withdrawalAmount);

        System.out.printf("account1 balance: $%.2f\n", account1.getBalance());
        System.out.printf("account2 balance: $%.2f\n", account2.getBalance());
    }
}

```

How can I get my "System.out.printf" dumped into a file (dumped as in not erasing the file's content)? Or perhaps creating separate files for each instance. Any help is appreciated beginner here. Thanks.

Answer: 
1) you can redirect stdout to a file when running your program

```
java AccountTest >> test.txt 

```

2) you can reassign stdout at the beginning of your program

```
    PrintStream out = new PrintStream(new FileOutputStream("test.txt", true));
    System.setOut(out);

```

3) you can use java.io.PrintWriter instead of System.out

```
    PrintWriter out = new PrintWriter(new FileWriter("test.txt", true));
    out.printf( "account1 balance: $%.2f\n", account1.getBalance() );

```
It depends on how you run this program. If you have a POSIX shell at hand, you can just redirect its standard output to a file.

The following would append to a log file:

```
$ java -jar myjar.jar >> log

```

this one would create a new epoch-dated log file each time (the `$(…)` might be a bash-specific feature, I'm not sure):

```
$ java -jar myjar.jar > log-$(date +%s)

```