【问题标题】:check if the image is in assets folder if image exists return its path in android检查图像是否在资产文件夹中如果图像存在返回它在android中的路径
【发布时间】:2014-09-21 21:20:47
【问题描述】:

我在资产文件夹中有一些图像。 现在我想要一个代码来检查图像是否存在。如果图像退出,那么它必须返回它的路径。 那么在android的assets文件夹中查找图像或文本文件路径的可能步骤是什么?

我使用了这种方法:但我想获取存储在 assets 文件夹中的图像的路径。

public String filePath(String image) throws IOException{
         String myfilepath = Environment.getExternalStorageDirectory().toString()+"/"+image;
            return myfilepath;

        }

【问题讨论】:

  • 哇!!!直接询问代码现在我想要一个代码来检查图像是否存在...
  • 意思是问方法找图片的路径!
  • 只有知道文件名或图片名,才能从Assert获取图片或文件。
  • 检查我编辑的问题!并给我关于如何获取存储在资产文件夹中的图像路径的建议!提前致谢。

标签: android image path assets


【解决方案1】:
public String filePath(String image,Context _context)
{
   File file = new File(_context.getCacheDir()+File.separator+image);

   if (file.exists()) 
      return file.getPath();
   else
      return null;       

}

【讨论】:

    【解决方案2】:

    首先你必须得到资产中所有文件的列表

    私有字符串 [] listAssetFiles(字符串路径) {

    字符串 [ ] 列表; 尝试 { list = getAssets().list(path); 如果 (list.length > 0) { // T

    his is a folder
                for (String file : list) {
                    if (!listAssetFiles(path + "/" + file))
    }
            } 
        } catch (IOException e) {
            return null;
        }
    return list; 
    }
    

    并调用 listAssetFiles("")

    【讨论】:

      猜你喜欢
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 2014-03-27
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多