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

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;
                  }

         }
}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。