1
在我StockTransaction.java,這首先運行爲什麼只有1個java源文件能夠寫入同一個文件?
try{
FileOutputStream fos = new FileOutputStream("C:"+File.separatorChar+"transactions.dat");
OutputStreamWriter osw = new OutputStreamWriter(fos);
BufferedWriter writer = new BufferedWriter(osw);
writer.append(aStockTransaction.toString());
writer.append("******This Transaction ends Here.*****");
writer.flush();
writer.close();}
然後在我的brokerageAccount.java,該跑最後一棒
try {
FileOutputStream fos = new FileOutputStream("C:"+File.separatorChar+"transactions.dat");
OutputStreamWriter osw = new OutputStreamWriter(fos);
BufferedWriter writer = new BufferedWriter(osw);
writer.append(brokerageAcc1.toString());
writer.append("******This is end of File*****");
writer.flush();
writer.close();
//System.out.println(brokerageAcc1.toString());
}
我的System.out.println測試安慰,輸出精。 但最終的文件只顯示brokerAcc1.toString(),沒有爲aStockTransaction.toString()。 爲什麼?如何解決它?提前致謝!