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 block
e.printStackTrace();
}
String s=baos.toString();
tv.setText(s);
Android /assets
最新推荐文章于 2024-02-06 15:14:59 发布