我的HashSet是否在输出csv文件中删除了一列?

时间:2017-10-01 05:52:26

标签: java csv

所以一切都在我的Java IDE中正确显示并按预期运行。我有它每隔几分钟就会自动写入csv文件的地方。我遇到的问题是" Meter 2"列没有显示,我觉得我的代码中的HashSet可能认为它是重复的并删除它。

以下是代码:

package HourMeter;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Hours {
Set<String> hour = new HashSet<>();
String filename;
/**
 * @param filename filename of the .csv file to update
 * @param addresses Array of Strings of addresses to add to the .csv file
 * @throws IOException Throws exception on incorrect filename
 */
public Hours(String filename, String[] addresses) throws IOException {
    if(filename==null) throw new IllegalArgumentException();
    this.filename = filename;
        try (BufferedReader reader = new BufferedReader(new 
FileReader("Hours.csv"))) {
            while(reader.ready())
            {
                hour.add(reader.readLine());
            }
        }

    if(addresses != null)
    {
                hour.addAll(Arrays.asList(addresses));
    }
}

Hours(String string) {
    throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
}

public void outputFile() throws IOException
{
        try (PrintWriter out = new PrintWriter("Hours.csv")) {
            hour.forEach((s) -> {
                out.println(s);
            });
        }   
}
}

以下是该计划和csv报告的照片。

enter image description here

enter image description here

正如您所看到的,csv报告缺少一组字符串值,米2.我应该考虑做什么或更改我的代码以在csv报告中进行此显示?谢谢您的帮助。我一直试图解决这个问题几天。任何帮助将不胜感激!

0 个答案:

没有答案