【发布时间】:2017-11-08 15:48:58
【问题描述】:
我正在尝试将我的 csv 文件转换为 kml 文件。 我构建了一个接收数组列表的方法。 我不明白为什么我得到的 kml 文件没有在谷歌地球上运行。
这是我的代码:
static void writeFileKML(ArrayList<String[]> a, String output) {
ArrayList<String> content = new ArrayList<String>();
String kmlstart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
content.add(kmlstart);
String kmlend = "</kml>";
try{
FileWriter fw = new FileWriter(output);
BufferedWriter bw = new BufferedWriter(fw);
for (int i = 1; i < a.size(); i++) {
String[] s = a.get(i);
String kmlelement ="<Placemark>\n" +
"<name>"+s[6]+"</name>\n" +
"<description>"+s[6]+"</description>\n" +
"<Point>\n" +
"<coordinates>"+s[3]+","+s[2]+"</coordinates>" +
"</Point>\n" +
"</Placemark>\n";
content.add(kmlelement);
}
content.add(kmlend);
String csv = content.toString().replaceAll(",", "").replace("[", "").replace("]", "");
bw.write(csv);
bw.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
函数获取的csv包含来自不同地方的多个wifi网络。
谢谢。
【问题讨论】:
-
请发布minimal reproducible example:包括简短的测试数据(输入数组列表),以及您期望的输出。