0

我正在开发一个 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;
    }
}

那么,我该怎么做呢?

此致

4

0 回答 0