如何JAVA格式日期
2011年4月6日
而不是0
2011年4月6日
?
我需要使用GregorianCalendar
GregorianCalendar today=new GregorianCalendar();
String todayStr = String.format("%1$tm/%1$td/%1$tY", today);
Run Code Online (Sandbox Code Playgroud)
给
04/06/2011
我想要
2011年4月6日
提前致谢
在我的StockTransaction.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();}
Run Code Online (Sandbox Code Playgroud)
然后在我的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());
}
Run Code Online (Sandbox Code Playgroud)
我用System.out.println测试了控制台,输出很好.但是结束文件只显示brokerAcc1.toString(),对于aStockTransaction.toString()没有任何内容.为什么?怎么解决?提前致谢!