欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

将java对象输出到本地txt文档

程序员文章站 2022-05-31 10:41:55
...
在程序中如何将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());
}
}
相关标签: 导出 txt java