在程序中如何将java对象输出到本地文档:这里列出一个小示例:
public
class WriteData2txt {
public static void WriteData4Gm(String exportData,String str) {
String imageName = getLocaltime2String();
try {
File file=new File("/root/"exportData"_"+str+"_" + imageName+ ".txt");
if (file.exists()) {
file.delete();
}
file.createNewFile();
BufferedWriter output = new BufferedWriter(new FileWriter(file));
output.write(exportData);
System.out.println("++++++++++++++++++++++++++++++++++++++++++");
System.out.println("导出成功!");
System.out.println("++++++++++++++++++++++++++++++++++++++++++");
output.close();
} catch (Exception ex) {
System.out.println(ex);
}
}
private static String getLocaltime2String() {
DateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss");
Calendar calendar = Calendar.getInstance();
return df.format(calendar.getTime());
}
}