本文介绍了如何获得资源的途径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的RandomAccessFile类来访问文件与我的应用程序附带。但是,该类只接受一个字符串,它是文件路径。如果我放在什么地方我的文件,如资产目录,我如何构建该文件的路径?我知道我可以使用getAssets方法读取的资源,但那些只返回不能中定位InputStreams。

I'd like to use the RandomAccessFile class to access a file that ships with my application. However, that class only accepts a String which is the path to the file. If I place my file somewhere like the assets directory, how do I construct a path to that file? I know I can use the getAssets methods to read up resources, but those only return InputStreams which cannot be seeked.

谢谢!

推荐答案

的Andr​​oid资源不打算直接访问作为文件。其实它们通常存储在.apk文件,所以他们不是在所有文件 - 只是压缩数据

Android resources aren't intended to be accessed directly as files. Actually they're usually stored in .apk, so they aren't files at all - just zipped data.

您可以做的InputStream对象的基本操作。如果你需要更先进的,那么你可以阅读整个文件到内存缓冲区或它的地方复制到一个真正的文件数据的分区或SD卡。

You could do basic manipulations on InputStream object. If you need something more advanced, then you could read whole file to a memory buffer or copy it to a real file somewhere on data partition or sdcard.

这篇关于如何获得资源的途径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:33