Android /assets

来源:互联网 发布:淘宝客收费公式 编辑:程序博客网 时间:2024/06/05 20:40
  Android提供一个/assets目录,可以将要包含在包中的文件放在这里。这个目录与/res具有相同的级别,也就是说它包含在/res子目录中。/assets中的文件不会在R.JAVA中生成资源ID,必须指定文件路径才能读取它们。文件路径是以/assets开头的相对路径。可以使用AssetManager类来访问这些文件。AssetManager asset=this.getAssets();    InputStream is;    ByteArrayOutputStream baos=new ByteArrayOutputStream();try {is = asset.open("PointerTrans.txt");        int i=is.read();    while(i!=-1){    baos.write(i);    i=is.read();    }} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}    String s=baos.toString();    tv.setText(s);