Creating CSV files using java
•
Java
I will use java to create a CSV file This is part of the code:
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');
The problem is that I successfully created the CSV file In the for loop, K3 is the time in the format of 15:40:23, July 22, 2013 But the second "23" cannot be displayed Others performed well If you have any questions, please help
This is the code of my class
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();
}
}
}
Solution
Expected output seconds of code They are visible in a text editor
They are only invisible in the spreadsheet application MS Excel One possible reason is that the column width is too small
[this answer summarizes the results of the dialogue between OP and me.]
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
