Is there a way to just add an image file into a kmz file using Java API for KML (JAK)? I can create a kml file with no problem, but I\'m trying to just embed a resources (su
Java comes with a default zip utility, all you need to do is to pass the kml file you need to zip along with the list of image files. These two functions should do the trick.
private void exportAsKmz(Kml kmlFile,File[] files) throws IOException {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream("example.kmz"));
addKmzFile(kmlFile,out,files);
out.close();
}
private void addKmzFile(Kml kmzFile, ZipOutputStream out,File[] files) throws IOException {
String fileName = "";
fileName = kmzFile.getFeature().getName();
if (!fileName.endsWith(".kml")) {
fileName += ".kml";
}
for(File file : files){
out.putNextEntry(new ZipEntry(file.getName()));
Files.copy(file.toPath(), out);
}
out.putNextEntry(new ZipEntry(URLEncoder.encode(fileName, "UTF-8")));
kmzFile.marshal(out);
out.closeEntry();
}