开发者

How to test cache dir?

I am downloading images using a imageAdapter extending a base class. Im storing them in cache here is where i test to see if they are in the cache

            URI imageUri = null;

            //Setting the Uri of aURL to imageUri.
            try {
            imageUri = aURL.toURI();

            } catch (URISyntaxException e1) {
          开发者_如何学Python  // TODO Auto-generated catch block
                e1.printStackTrace();
                        }



                //Testing to see if images are already in cache, if not then we load the images from the web and save them to the cache.
           if (new File(new File(myContext.getCacheDir(), "thumbnails"), "" + imageUri.hashCode()).exists())
                           {

        Log.v("Loader", "File exists in cache. Now pulling from the cache");

        String cachFile = myContext.getCacheDir() +"/thumbnails/"+imageUri.hashCode();
        FileInputStream fis;

My Question is how do i test this cache dir "thumbnails in another method in the application?


To test that a file is in the cache directory or not, just use

File f = new File("<path_to_your_file>");
f.exists(); //TRUE if the file exists, FALSE otherwise.

In your case, you can use the same code on other methods since myContext.getCacheDir() will return the same directory throughout the application.

But, on the other methods, you still need to know imageUri to test.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜