Android examples for App:Assets File
copy File From Assets
//package com.java2s; import android.content.Context; import android.content.res.Resources; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { private final static int BUFFER_SIZE = 1024 * 1024; public static void copyFileFromAssets(Context context, String fileName, File outputFile) {/*from w ww .j a va 2 s. co m*/ byte[] buffer = new byte[BUFFER_SIZE]; int bytesCount; try { InputStream imageStream = context.getAssets().open(fileName); FileOutputStream fileOutputStream = new FileOutputStream( outputFile); while ((bytesCount = imageStream.read(buffer)) >= 0) { fileOutputStream.write(buffer, 0, bytesCount); } fileOutputStream.close(); imageStream.close(); } catch (IOException | Resources.NotFoundException e) { e.printStackTrace(); } } }