什么是我的Android应用程序的根?

时间:2012-12-24 12:52:18

标签: android

我正在尝试开发一个简单的Android应用程序。我想知道我的某个应用程序文件夹中是否存在图像,但我不知道我的应用程序的根目录是什么。我试过......

File nomeFile = new File("res/drawable-hdpi/imagename.jpg")
File nomeFile = new File("myappanem/res/drawable-hdpi/imagename.jpg")

......但它不起作用。

3 个答案:

答案 0 :(得分:1)

试试这个:

File YourFile = new File(Environment.getExternalStorageDirectory(), "/Android/data/....yourfile.txt");

答案 1 :(得分:0)

打包后,您无法访问drawable或manifest。因为根本没有“可绘制”文件夹或清单文件。安装后,所有drawables都包装在APK文件中。你无法联系到他们。 但您可以在应用中访问手机的任何文件夹。

首先制作目录。

File directory = new File(Environment.getExternalStorageDirectory()+File.separator  
+"Your folder");
  directory.mkdirs();

像这样访问你的文件夹。

 String fileUrl = "/Your folder/a.png";

 String file = android.os.Environment.getExternalStorageDirectory().getPath() +  
 fileUrl;
File f = new File(file);

答案 2 :(得分:0)

您是否考虑了应用程序缓存目录的内部存储器      //将此用作内存

     String path =Environment.getDataDirectory().getAbsolutePath();
    File myImage=new File(path,"your file name.extension");

     //use this for cache directory     

    String path=getApplicationContext().getDir("" , Context.MODE_PRIVATE);
    File myImage=new File(path,"your file name.extension")
相关问题