Android 从资产目录Assert中复制东西的工具类

时间:2014-01-14 21:48:17   收藏:0   阅读:654

package com.itheima.mobilesafe.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.content.Context;

public class AssetCopyUtils {  
         public static File copy(Context context, String fileName, String destPath) {
                  try {
                        InputStream is = context.getAssets().open(fileName);
                        File file = new File(destPath);
                        FileOutputStream fos = new FileOutputStream(file);
                        byte[] buffer = new byte[1024];
                        int len = 0;

                        while ((len = is.read(buffer)) != -1) {
                              fos.write(buffer, 0, len);
                        }
                       fos.flush();
                       fos.close();
                       is.close();
                       return file;
                  } catch (Exception e) {
                      e.printStackTrace();
                      return null;
                  }

         }
}

原文:http://www.cnblogs.com/zhangping/p/3513833.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!