1

私のアプリケーションでは、ブラウザー フィールドに html テンプレートと画像を使用し、sdcard に保存しました。今、そのhtml、画像ファイルを圧縮してPHPサーバーに送信したいと思います。そのファイルを圧縮してサーバーに送信するにはどうすればよいですか? 非常に役立つサンプルをいくつか提供してください。

私はこの方法を試しました...私のコードは

編集:

private void zipthefile() {
    String out_path = "file:///SDCard/" + "newtemplate.zip";
    String in_path = "file:///SDCard/" + "newtemplate.html";
    InputStream inputStream = null;
    GZIPOutputStream os = null;
    try {
        FileConnection fileConnection = (FileConnection) Connector
                .open(in_path);//read the file from path
        if (fileConnection.exists()) {
            inputStream = fileConnection.openInputStream();
        }

        byte[] buffer = new byte[1024];

        FileConnection path = (FileConnection) Connector
                .open(out_path,
                        Connector.READ_WRITE);//create the out put file path

        if (!path.exists()) {
            path.create();
        }
        os = new GZIPOutputStream(path.openOutputStream());// for create the gzip file

        int c;

        while ((c = inputStream.read()) != -1) {
            os.write(c);
        }
    } catch (Exception e) {
        Dialog.alert("" + e.toString());
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
                Dialog.alert("" + e.toString());
            }
        }
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
                Dialog.alert("" + e.toString());
            }
        }
    }

}

このコードは単一のファイルに対しては正常に機能しますが、フォルダー内のすべてのファイル (複数のファイル) を圧縮したいと考えています。

4

1 に答える 1