从另一个程序获得 Assests 文件夹下的东西
2012-04-10 13:57
344 查看
Resources r = this.getResources();
AssetManager a = r.getAssets();
String[] list = a.list("/");
Log.d("test", "Length
of / is "+list.length);
for (String s : list) {
Log.d("test", s);
}
按照上面的写法是错误的 String[] names = am.list(""); 中间是空格
也可以AssetManager am = this.getAssets();
String[] names = am.list("");
如果是asset下的子文件夹String[] names= am.list("subfolder");
如果是asset下的文件InputStream in = am.open("file.png");
子文件夹下的文件 InputStream in = am.open("subfolder/file.png");
然后使用
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
3.
void displayFiles (AssetManager mgr, String path) {
try {
String list[] = mgr.list(path);
if (list != null)
for (int i=0; i<list.length; ++i)
{
Log.v("Assets:", path +"/"+ list[i]);
displayFiles(mgr, path + "/" + list[i]);
}
} catch (IOException e) {
Log.v("List error:", "can't
list" + path);
}
一定注意加/
4.这个问题还会遇到解析出来的是系统目录
http://groups.google.com/group/android-developers/browse_thread/thread/2b110c3c30d8df93/7d8191d6302bca2c?pli=1
参看这里
Did this code:
try
{
String fileArray[] = context.getAssets().list( "" );
if( fileArray != null)
for( int i = 0; i < fileArray.length; ++i )
{
Log.v( " ASSETS_DIR File", fileArray[i] );
try
{
String subfileArray[] =
context.getAssets().list( fileArray[i] );
if( subfileArray != null)
for( int j = 0; j < subfileArray.length; ++j )
{
Log.v( " ASSETS_SUBDIR File", fileArray[i] + ":" +
subfileArray[j] );
}
}
catch( IOException e)
{
Log.e( "ASSETS_SUBDIR", "Can't List files!" );
}
}
}
catch( IOException e)
{
Log.e( "ASSETS_DIR", "Can't List files!" );
}
And got the following result.
DUMP from logcat !
V/ASSETS_DIR File(7570): images
V/ASSETS_SUBDIR File(7570): images:corky.png
V/ASSETS_SUBDIR File(7570): images:cylon_dot.png
V/ASSETS_SUBDIR File(7570): images:cylon_left.png
V/ASSETS_SUBDIR File(7570): images:cylon_right.png
V/ASSETS_SUBDIR File(7570): images:violet.png
V/ASSETS_DIR File(7570): skins
V/ASSETS_SUBDIR File(7570): skins:contact-andy-rubin.png
V/ASSETS_SUBDIR File(7570): skins:contact-larry-page.png
V/ASSETS_DIR File(7570): sounds
V/ASSETS_SUBDIR File(7570): sounds:bootanim0.raw
V/ASSETS_SUBDIR File(7570): sounds:bootanim1.raw
V/ASSETS_DIR File(7570): webkit
V/ASSETS_SUBDIR File(7570): webkit:missingImage.png
V/ASSETS_SUBDIR File(7570): webkit:nullplugin.png
V/ASSETS_SUBDIR File(7570): webkit:textAreaResizeCorner.png
void displayFiles (AssetManager mgr, String path) {
try {
String list[] = mgr.list(path);
if (list != null)
for (int i=0; i<list.length; ++i)
{
Log.v("Assets:", path +"/"+ list[i]);
displayFiles(mgr, path + list[i]);
}
} catch (IOException e) {
Log.v("List error:", "can't list" + path);
}
}
AssetManager mgr = new AssetManager();
displayFiles(mgr, "/");
prints:
V/Assets: (13257): //AndroidManifest.xml
V/Assets: (13257): //META-INF
V/Assets: (13257): //assets
V/Assets: (13257): //res
V/Assets: (13257): //resources.arsc
displayFiles(mgr, "");
prints:
displayFiles(mgr, "");
prints:
V/Assets: (14399): /images
V/Assets: (14399): images/corky.png
V/Assets: (14399): images/cylon_dot.png
V/Assets: (14399): images/cylon_left.png
V/Assets: (14399): images/cylon_right.png
V/Assets: (14399): images/violet.png
V/Assets: (14399): /skins
V/Assets: (14399): skins/contact-andy-rubin.png
V/Assets: (14399): skins/contact-larry-page.png
V/Assets: (14399): /sounds
V/Assets: (14399): sounds/bootanim0.raw
V/Assets: (14399): sounds/bootanim1.raw
V/Assets: (14399): /webkit
V/Assets: (14399): webkit/missingImage.png
V/Assets: (14399): webkit/nullplugin.png
V/Assets: (14399): webkit/textAreaResizeCorner.png
AssetManager a = r.getAssets();
String[] list = a.list("/");
Log.d("test", "Length
of / is "+list.length);
for (String s : list) {
Log.d("test", s);
}
按照上面的写法是错误的 String[] names = am.list(""); 中间是空格
也可以AssetManager am = this.getAssets();
String[] names = am.list("");
如果是asset下的子文件夹String[] names= am.list("subfolder");
如果是asset下的文件InputStream in = am.open("file.png");
子文件夹下的文件 InputStream in = am.open("subfolder/file.png");
然后使用
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
3.
void displayFiles (AssetManager mgr, String path) {
try {
String list[] = mgr.list(path);
if (list != null)
for (int i=0; i<list.length; ++i)
{
Log.v("Assets:", path +"/"+ list[i]);
displayFiles(mgr, path + "/" + list[i]);
}
} catch (IOException e) {
Log.v("List error:", "can't
list" + path);
}
一定注意加/
4.这个问题还会遇到解析出来的是系统目录
http://groups.google.com/group/android-developers/browse_thread/thread/2b110c3c30d8df93/7d8191d6302bca2c?pli=1
参看这里
Did this code:
try
{
String fileArray[] = context.getAssets().list( "" );
if( fileArray != null)
for( int i = 0; i < fileArray.length; ++i )
{
Log.v( " ASSETS_DIR File", fileArray[i] );
try
{
String subfileArray[] =
context.getAssets().list( fileArray[i] );
if( subfileArray != null)
for( int j = 0; j < subfileArray.length; ++j )
{
Log.v( " ASSETS_SUBDIR File", fileArray[i] + ":" +
subfileArray[j] );
}
}
catch( IOException e)
{
Log.e( "ASSETS_SUBDIR", "Can't List files!" );
}
}
}
catch( IOException e)
{
Log.e( "ASSETS_DIR", "Can't List files!" );
}
And got the following result.
DUMP from logcat !
V/ASSETS_DIR File(7570): images
V/ASSETS_SUBDIR File(7570): images:corky.png
V/ASSETS_SUBDIR File(7570): images:cylon_dot.png
V/ASSETS_SUBDIR File(7570): images:cylon_left.png
V/ASSETS_SUBDIR File(7570): images:cylon_right.png
V/ASSETS_SUBDIR File(7570): images:violet.png
V/ASSETS_DIR File(7570): skins
V/ASSETS_SUBDIR File(7570): skins:contact-andy-rubin.png
V/ASSETS_SUBDIR File(7570): skins:contact-larry-page.png
V/ASSETS_DIR File(7570): sounds
V/ASSETS_SUBDIR File(7570): sounds:bootanim0.raw
V/ASSETS_SUBDIR File(7570): sounds:bootanim1.raw
V/ASSETS_DIR File(7570): webkit
V/ASSETS_SUBDIR File(7570): webkit:missingImage.png
V/ASSETS_SUBDIR File(7570): webkit:nullplugin.png
V/ASSETS_SUBDIR File(7570): webkit:textAreaResizeCorner.png
void displayFiles (AssetManager mgr, String path) {
try {
String list[] = mgr.list(path);
if (list != null)
for (int i=0; i<list.length; ++i)
{
Log.v("Assets:", path +"/"+ list[i]);
displayFiles(mgr, path + list[i]);
}
} catch (IOException e) {
Log.v("List error:", "can't list" + path);
}
}
AssetManager mgr = new AssetManager();
displayFiles(mgr, "/");
prints:
V/Assets: (13257): //AndroidManifest.xml
V/Assets: (13257): //META-INF
V/Assets: (13257): //assets
V/Assets: (13257): //res
V/Assets: (13257): //resources.arsc
displayFiles(mgr, "");
prints:
displayFiles(mgr, "");
prints:
V/Assets: (14399): /images
V/Assets: (14399): images/corky.png
V/Assets: (14399): images/cylon_dot.png
V/Assets: (14399): images/cylon_left.png
V/Assets: (14399): images/cylon_right.png
V/Assets: (14399): images/violet.png
V/Assets: (14399): /skins
V/Assets: (14399): skins/contact-andy-rubin.png
V/Assets: (14399): skins/contact-larry-page.png
V/Assets: (14399): /sounds
V/Assets: (14399): sounds/bootanim0.raw
V/Assets: (14399): sounds/bootanim1.raw
V/Assets: (14399): /webkit
V/Assets: (14399): webkit/missingImage.png
V/Assets: (14399): webkit/nullplugin.png
V/Assets: (14399): webkit/textAreaResizeCorner.png
相关文章推荐
- 无法完成,因为文件或文件夹已经在另一个程序中打开,请关闭该文件在重试
- Linux下复制文件夹下所有东西到另一个文件夹(包括隐藏文件)
- 拖文件夹或者文件到可执行程序上,获得文件完整路径的方式
- 获得当前执行程序所在文件夹路径
- Win7-其中的文件夹或文件已在另一个程序中打开
- matlab 实践程序8——将指定的图像移动到另一个文件夹
- win7文件夹或文件已在另一个程序中打开
- Linux下复制文件夹下所有东西到另一个文件夹(包括隐藏文件)
- 程序片段----批处理获得文件夹下所有文件的名称
- [VB.NET]怎样才能在自己的程序自动运行后获得系统中被点击文件夹的路径?(下)
- 程序片段----使用Windows api 获得系统时间并生成文件夹
- VC根据进程名获得进程ID 和 VC获得系统特殊文件夹 SHGetSpecialFolderPath 和 VC写入注册表,使程序开机启动
- CFolderDialog,CFolderPickerDialog选择文件夹及获得当前程序路径
- 获得当前程序路径
- windows 使用bat脚本文件,复制文件夹到另一个盘
- IIS:另一个程序正在使用此文件,进程无法访问
- matlab从文件夹名中获得该文件夹下所图像文件名
- 如何在一个程序集中序列化在另一个中反序列化
- python程序2(递归查找某一个文件夹下所有的文件是否含有某个特定的字符串,并打印该文件名)