我将使用java创建CSV文件。以下是代码的一部分:
try{
FileWriter writer = new FileWriter(sFileName);
writer.append("Title");
for(StoredArticle sa3:historyFile.keySet()){
for(String k3:sa3.getTimeAndPopularity().keySet()){
writer.append(',');
writer.append(k3);
}
}
writer.append('\n');
问题是我成功创建了CSV文件。并且在for循环中,k3是以格式2013/07/22 15:40:23.
表示的时间但是秒“23”无法显示。其他人表现良好。有什么问题请帮忙。
这是我全班的代码
package uk.ac.ncl.fanyaoxia.createCSV;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import uk.ac.ncl.fanyaoxia.monitor.MonitorRecentUpdates;
import uk.ac.ncl.fanyaoxia.monitor.StoredArticle;
import uk.ac.ncl.fanyaoxia.webpagefetch.ReadXml;
public class CreateCSVFile {
private static Map < StoredArticle, ReadXml > historyFile;
public CreateCSVFile() {
historyFile = new HashMap < StoredArticle, ReadXml > ();
}
public void createFile() {
generateCsvFile("HistoryTable.csv");
}
private static void generateCsvFile(String sFileName) {
MonitorRecentUpdates csvFile = new MonitorRecentUpdates();
historyFile = csvFile.getMap();
try {
FileWriter writer = new FileWriter(sFileName);
writer.append("Title");
for (StoredArticle sa3: historyFile.keySet()) {
for (String k3: sa3.getTimeAndPopularity().keySet()) {
writer.append(',');
writer.append(k3);
}
}
writer.append('\n');
for (StoredArticle sa3: historyFile.keySet()) {
writer.append(sa3.getStoredTitle());
for (String k3: sa3.getTimeAndPopularity().keySet()) {
writer.append(',');
writer.append(sa3.getTimeAndPopularity().get(k3).toString());
}
writer.append('\n');
}
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:3)
代码预期输出秒数。它们在文本编辑器中可见。
它们在电子表格应用程序MS Excel中不可见。一个可能的原因是列宽太小。
[这个答案总结了OP和我之间的对话结果。]