[Android]KMZファイルの作成 [テレビ・エンタメ]
KMZファイルの作成
ZipEntryのとこでちょっとハマったのでメモ
ZipEntryのとこでちょっとハマったのでメモ
// KMZ // 入力対象のファイル String inputFiles[] = new String[3]; inputFiles[0] = "doc.kml"; inputFiles[1] = "pic" + strTime + ".jpg"; inputFiles[2] = "map" + strTime + ".png"; // 入力ストリーム InputStream is = null; // ZIP形式の出力ストリーム ZipOutputStream zos = null; // 入出力用のバッファを作成 byte[] buf = new byte[1024]; // ZipOutputStreamオブジェクトの作成 try { zos = new ZipOutputStream(new FileOutputStream(dataroot + "" + strTime + ".kmz")); for (int i = 0; i < inputFiles.length; i++) { is = new FileInputStream(tmpDir.getPath() + "/" + inputFiles[i]); // ZIPエントリを作成。名前は入力ファイルのファイル名 ZipEntry ze = null; if (i == 0) // "doc.kml"以外はfilesフォルダに入れてる ze = new ZipEntry(inputFiles[i]); else ze = new ZipEntry("files/" + inputFiles[i]); // 先頭に / があるとダメ // 作成したZIPエントリを登録 zos.putNextEntry(ze); // 入力ストリームからZIP形式の出力ストリームへ書き出す int len = 0; while ((len = is.read(buf)) != -1) { zos.write(buf, 0, len); } // 入力ストリームを閉じる is.close(); // エントリをクローズする zos.closeEntry(); } } catch (FileNotFoundException e2) { e2.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (zos != null) { try { zos.close(); } catch (IOException e) { e.printStackTrace(); } } }
タグ:Android
とても魅力的な記事でした!!
また遊びに来ます!!
ありがとうございます。。
by 履歴書の書き方の見本 (2011-10-10 17:55)