用java创建csv文件

用java创建csv文件,java,google-analytics,export-to-csv,Java,Google Analytics,Export To Csv,我正在尝试将打印方法改为csv private static void printGaData(GaData results) { System.out.println( "printing results for profile: " + results.getProfileInfo().getProfileName()); if (results.getRows() == null || results.getRows(

我正在尝试将打印方法改为csv

    private static void printGaData(GaData results) { 
        System.out.println( 
            "printing results for profile: " + results.getProfileInfo().getProfileName()); 

        if (results.getRows() == null || results.getRows().isEmpty()) { 
          System.out.println("No results Found."); 
        } else { 

          // Print column headers. 
          for (ColumnHeaders header : results.getColumnHeaders()) { 
            System.out.printf("%30s", header.getName()); 
          } 
          System.out.println(); 

          // Print actual data. 
          for (List<String> row : results.getRows()) { 
            for (String column : row) { 
              System.out.printf("%30s", column); 
            } 
            System.out.println(); 
          } 

          System.out.println(); 
        } 
      }
都在A列中,有很多空格。如何解决这个问题?

我想您需要

for (String column : row) {
       pw.printf(column + ", "); // not row
}

是的,我刚刚意识到,但在我把它改成列之后,csv是空的,我改变了代码,然后我在一列(A列)中得到了三列数据,带有空格。如何将其解析为三列?T.T…pw.printf(column,“,”)没有打印任何内容,我使用pw.printf(“%30s”,column,“,”),为所有三列打印一列数据您需要关闭PrintWriter我将pw.close()放在System.out.println之后(“未找到结果”);它不能解决1列的问题。因此,您的问题似乎是,传递给printGaData的GaData结果包含数据,但ExportGaData中没有数据-告诉我们您是如何调用它的。
columnA's data    columnb's data    columnC's data
for (String column : row) {
       pw.printf(column + ", "); // not row
}