我是Java中的数据库的新手,我试图导出1表中的数据并将其存储在文本文件中。目前下面的代码写入文本文件,但全部在一行?谁能帮忙?我如何从数据库获取数据并将其存储到文本文件中?
我的代码
private static String listHeader() {
String output = "Id Priority From Label Subject\n";
output += "== ======== ==== ===== =======\n";
return output;
}
public static String Export_Message_Emails() {
String output = listHeader();
output +="\n";
try {
ResultSet res = stmt.executeQuery("SELECT * from messages ORDER BY ID ASC");
while (res.next()) { // there is a result
output += formatListEntry(res);
output +="\n";
}
} catch (Exception e) {
System.out.println(e);
return null;
}
return output;
}
public void exportCode(String File1){
try {
if ("Messages".equals(nameOfFile)){
fw = new FileWriter(f);
//what needs to be written here
//fw.write(MessageData.listAll());
fw.write(MessageData.Export_Message_Emails());
fw.close();
}
}
我在哪里编写System.llineSeparator(); – 2015-02-11 12:59:30
而不是输出+ =“\ n”写输出+ = System.lineSeparator() – 2015-02-11 13:02:09