鑑於我的代碼:輸出控制檯到文本文件? - Java的
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());
}
}
我怎樣才能讓我的「System.out.printf」轉儲到一個文件中(如傾倒在不刪除該文件的內容)?或者可能爲每個實例創建單獨的文件。任何幫助感謝初學者在這裏。謝謝。
已經有答案了。 http://stackoverflow.com/questions/1994255/how-to-write-console-output-to-a-txt-file?rq=1 – Kaliber64 2013-02-16 03:02:34
如果我沒有錯誤,將讀取輸入行然後保存到文本文件。請注意,在我的代碼中,我不打算在控制檯上輸入任何內容。 – Alexander 2013-02-16 03:07:37
@ user2077545查看該問題中最受好評的答案:http://stackoverflow.com/a/1994283/1211906 – 2013-02-16 03:11:00