大家好,在得到一些建议后,我试图使用filewriter方法导出我的谷歌分析查询,我得到的是CSV文件格式,这是我到目前为止所拥有的
private static void printGaData(GaData results) {
try {
PrintWriter pw = new PrintWriter(BufferedWriter(new FileWriter("data.csv")));
}
catch(Exception e) {
e.printStackTrace();
}
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(header.getName() + ", ");
}
System.out.println();
// Print actual data.
for (List<String> row : results.getRows()) {
for (String column : row) {
pw.printf(row + ", ");
}
pw.println();
}
pw.println();
}
}
}
不输出任何数据,并且一直说pw是非范围的,并且像那样
答案 0 :(得分:0)
您的PrintWriter位于try catch块中。如果你在外面定义它
PrintWriter pw = null;
try {
pw = new PrintWriter(BufferedWriter(new FileWriter("data.csv")));
} catch (Exception e) {
// handle exception
}
然后它将可用于其余代码。