Java tutorial
//package com.java2s; /* * Copyright (C) 2014 The AppCan Open Source Project. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ import android.content.Context; import android.content.res.AssetManager; import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; public class Main { private static boolean copyDex(Context ctx, String dexAssertPath, String dexPath) { AssetManager assets = ctx.getAssets(); InputStream inStream = null; OutputStream dexWriter = null; boolean suc = true; try { inStream = assets.open(dexAssertPath); FileOutputStream outStream = new FileOutputStream(dexPath); dexWriter = new BufferedOutputStream(outStream); byte[] buf = new byte[1024 * 8]; int len; while ((len = inStream.read(buf)) > 0) { dexWriter.write(buf, 0, len); } dexWriter.close(); inStream.close(); } catch (Exception e) { e.printStackTrace(); suc = false; } finally { try { if (null != inStream) { inStream.close(); } if (null != dexWriter) { dexWriter.close(); } } catch (Exception e) { e.printStackTrace(); } } return suc; } }