解决方案 »

  1.   


    public class TestApplicition extends Application {
    @Override
    public void onCreate() {
    super.onCreate();
    String sdPath=Environment.getExternalStorageDirectory().getAbsolutePath();
    String filePath = sdPath + File.separator + "Test" + File.separator + "img"+File.separator;
    File file = new File(filePath);
    if (file.exists()) {
    Log.i("TestApplicition", "file exists");
    } else {
    Log.i("TestApplicition", "file not exists");
    AssetManager am= this.getAssets();
    InputStream in=null;
    OutputStream out=null;
    try {
    String imgs[]=am.list("img");
    for(String name:imgs){
    in= am.open("img"+File.separator+name);
    out=new FileOutputStream(new File(filePath+name));
    copyFile(in, out);
    out.flush();
    out.close();
    in.close();
    out=null;
    in=null;
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    am.close();
    }
    }

    private void copyFile(InputStream in,OutputStream out) throws IOException{
    byte buffer[]=new byte[1024]; 
    while(in.read(buffer)!=-1){
    out.write(buffer);
    }
    }
    }
      

  2.   

    am.close(),这句加了,就抛异常,但是我觉得,总不能不关吧