Like you, my situation is much simpler if I can use an instance of RandomAccessFile . The solution I finally came to is to simply copy the resource to a file in the cache, and then open this file using RandomAccessFile :
private File createCacheFile(Context context, int resourceId, String filename) throws IOException { File cacheFile = new File(context.getCacheDir(), filename); if (cacheFile.createNewFile() == false) { cacheFile.delete(); cacheFile.createNewFile(); }
You should use this method:
File cacheFile = createCacheFile(context, resourceId, "delete-me-please"); RandomAccessFile randomAccessFile = new RandomAccessFile(cacheFile, "r"); // Insert useful things that people want. randomAccessFile.close(); cacheFile.delete();
source share