现有一问题,我要获取assets目录下文件的File对象或URI对象,查询资料发现对assets目录有两种使用方法,一种就是通过AssetsManager来获取inputStream对象的情况,还有就是就是说通过file:///android_assets/…这个路径可获取,但是发现还是不能获取到文件对象,求大神解救,不需要inputStream,要要File Object 或者 URI Object,谢谢了……

解决方案 »

  1.   

    File f = new File("assets/1.txt");
      

  2.   

    context.getAssets().open(sourceapkname);
      

  3.   

            private static String DB_PATH = "/mnt/sdcard/";
    private static String DB_NAME = "Termb.Lic";
    private static String ASSETS_NAME = "Termb.Lic";//这个就是assets下的一个文件/**
     * 复制assets下的文件时用这个方法
     * @throws IOException
     */
    private void copyBigDataBase() throws IOException {
    InputStream myInput;
    File dir = new File(DB_PATH);
    if (!dir.exists()) {
    dir.mkdirs();
    }
    File dbf = new File(DB_PATH + DB_NAME);
    if (dbf.exists()) {
    dbf.delete();
    }
    String outFileName = DB_PATH + DB_NAME;
    OutputStream myOutput = new FileOutputStream(outFileName);
    myInput = this.getAssets().open(ASSETS_NAME);
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
    myOutput.write(buffer, 0, length);
    }
    myOutput.flush();
    myInput.close();
    myOutput.close();
    }
      

  4.   

    file:///android_assets这种只能是里面放html,用webview访问才可以,否则只能用流
      

  5.   

    AssetManager asset=this.getAssets();
    InputStream is=null;
    try {
        is=asset.open("airport.txt");
        ......
    }catch{
        ......
    }
    ......