How to get the path to resources?

I would like to use the RandomAccessFile class to access the file that comes with my application. However, this class only accepts a string, which is the path to the file. If I put my file somewhere, like a resource directory, how do I create a path to this file? I know that I can use getAssets methods to read resources, but those return InputStreams that cannot be found.

Thank!

+3
source share
3 answers

I don’t know if you just skipped reading, but I find a lot of methods available that take String as input.

Check the AssetManager documentation , you will find methods such as:

final String[]   list(String path)
Return a String array of all the assets at the given path.

final InputStream    open(String fileName, int accessMode)
Open an asset using an explicit access mode, returning an InputStream to read its contents.
final InputStream    open(String fileName)
Open an asset using ACCESS_STREAMING mode.

, , list, , open.

0

- - , Android 2.2. RandomAccessFile. , InputStream : reset() (long) ,: -)

0

Android . .apk, - .

You can do basic manipulations with the InputStream object. If you need something more advanced, you can read the entire file into the memory buffer or copy it to a real file somewhere on the data section or SD card.

0
source

Source: https://habr.com/ru/post/1764087/


All Articles