将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());
}
}
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());
}
}
上一篇: Java获取TXT文本和Word文件的内容并显示在页面
下一篇: java读取txt文件
推荐阅读