DzouSi DzouSi -4 years ago 165
Android Question

inputStream gives

I have created new thread in my android app to read .p12 file like this:

AssetManager am = getAssets();
InputStream inputStream ="C:\\Users\\UkrBikeApp-ff55878cb577.p12");

This file exist in directory. But every time I get

The simular code works in simple java app without any problems. What is the reason?

Answer Source

First, C:\\Users\\UkrBikeApp-ff55878cb577.p12 is a path to a file on a Windows machine. Android is not Windows.

Second, C:\\Users\\UkrBikeApp-ff55878cb577.p12 is a filesystem path. It is not a path to an asset within your APK, and so AssetManager would not know what to do with it anyway.

If you want to package this file in your app:

  • Create an assets/ directory in the appropriate module and source set (e.g., app/src/main/assets/)

  • Put the file in assets/

  • Use open() on AssetManager with the plain filename

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download