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()。 为什么?如何解决它?提前致谢!