用输入流获得一个资源:
InputStream inputStream = getResources().getAssets().open(“logo.png”);
imageView.setImageBitmap(BitmapFactory.decodeStream(inputStream));
//获得Assets/files目录,Assets/files里的files好像是getFilesDir()里的Files
File FILE_DIR = getContext().getFilesDir();
//然后读取目录里的所有文件
loadFileList(FILE_DIR);
private void loadFileList(File path) {
this.currentPath = path;
List<String> r = new ArrayList<String>();
if (path.exists()) {
//if (path.getParentFile() != null) r.add(PARENT_DIR);
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String filename) {
File sel = new File(dir, filename);
if (!sel.canRead()) return false;
if (sel.getName().equals("instant-run")) return false;
return true;
}
};
String[] fileList1 = path.list(filter);
for (String file : fileList1) {
if (file.contains("."))
file = file.substring(0, file.lastIndexOf('.'));
r.add(file);
}
}
fileList = (String[]) r.toArray(new String[]{});
}
删除Assets/files目录下的文件
mContext.deleteFile(“测试.xml”);
用OutputStream可以往Assets/files目录下写入一个文件,但是比较复杂。就不写了。
Assets目录是不被编译的资源目录,是可读可写的。用上下文活动就能直接get读和delete删除。