如何只将唯一值写入CSV文件?

时间:2016-04-20 09:31:26

标签: java csv cloc

我正在开发一个CLOC程序,该程序遍历其他程序的源代码并从中获取值!,使用以下命令将一些值保存到CSV文件中:

out.write 

问题在于,我运行程序的次数与将在文件中写入的值一样多,尽管它们已经存在或不存在!

我的问题是如何告诉程序只写出尚未提供的值!

这是我的代码:

 private void writeReport() {
    BufferedWriter out = null;
    try {
        File file = new File("out.csv");
        boolean exists = file.exists();
        FileWriter fstream = new FileWriter(file, exists /*=append*/);
        out = new BufferedWriter(fstream);
        if (!exists) {
            out.write("Project Name;");
            out.write("Version;");
            out.write("Download Date;");
            out.write("Total Lines of Code;");
            out.write("Executable Lines;");
            out.write("Lines of Comments;");
            out.write("Trivial Lines;");
            out.write("Empty Lines;");
            out.write("Code Complexity;");
            out.write("Number of Files;"); //to be changed to numver of files 
            out.write("Average File Complexity;"); //to be changed to averag file complexity
            out.write("Total Comment Percentage;"); //total

            out.write("Total Lines of Test Code;");
            out.write("Excutable Test Lines;");
            out.write("Lines of Comments in Tests;");
            out.write("Trivial Lines in Tests;");
            out.write("Empty Lines in Tests;");
            out.write("Number of Test Files;");
            out.write("Comment Presentage in Test;");

            out.write(System.getProperty("line.separator"));

        }

        //  for (int i = 0; i < newFiles.getNrOfFiles(); i++) {
       // out.write("test" + ";");
        // out.write(newFiles.getParser(i).getSourceFile().getName()+ ";");
        out.write(String.valueOf(newFiles.getProjectName()) + ";");
        out.write(String.valueOf(newFiles.getVersionNumber()) + ";");
        out.write(String.valueOf(newFiles.getDownloadDate()) + ";");
        out.write(String.valueOf(newFiles.sumLinesOfCode()) + ";");
        out.write(String.valueOf(newFiles.sumLinesOfStatements()) + ";");
        out.write(String.valueOf(newFiles.sumLinesOfComments()) + ";");
        out.write(String.valueOf(newFiles.sumTrivialLines()) + ";");
        out.write(String.valueOf(newFiles.sumEmptyLines()) + ";");
        out.write(String.valueOf(newFiles.sumComplexity()) + ";");
        out.write(String.valueOf(newFiles.getNrOfFiles()) + ";");
        out.write(String.valueOf(newFiles.sumAvgComplexity()) + ";");
        out.write(String.valueOf((100 * newFiles.sumLinesOfComments()) / newFiles.sumLinesOfCode() + "%") + ";");
        out.write(String.valueOf(testFiles.sumLinesOfCode()) + ";");
        out.write(String.valueOf(testFiles.sumLinesOfStatements()) + ";");
        out.write(String.valueOf(testFiles.sumLinesOfComments()) + ";");
        out.write(String.valueOf(testFiles.sumTrivialLines()) + ";");
        out.write(String.valueOf(testFiles.sumEmptyLines()) + ";");
        out.write(String.valueOf(testFiles.getNrOfFiles()) + ";");
        out.write(String.valueOf((100 * testFiles.sumLinesOfComments()) / testFiles.sumLinesOfCode() + "%") + ";");

        out.write(System.getProperty("line.separator"));

      //  }

        //Close the output stream
        out.close();
    } catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
        //  return;
    }
}

那么,我该怎么做?

祝你好运

0 个答案:

没有答案