Waypoint
Waypoint

Reputation: 17753

Converting inputStream to FileInputStream?

I am in a problem - i need to read SecretKey from Android APK (e.g. key.keystore), for my app it has to be read as a FileInputStream, but from assets I am getting only inputStream. How to convert inputStream to FileInputStream? Or is there any other way, how to acces file from e.g. resources as a fileInputStream?

Thanks

Upvotes: 6

Views: 16609

Answers (3)

dmon
dmon

Reputation: 30168

Why do you need a FileInputStream specifically? In general, you don't have to care about the underlying implementation of the InputStream, you just read from it. Maybe your implementation should be InputStream agnostic.

Upvotes: 8

aromero
aromero

Reputation: 25761

I think you are referring to AssetManager.open() that returns an InputStream. There is no need to "convert" it to a FileInputStream, just get the reference to the InputStream and use it (wrap it in a BufferedInputStream if you want).

Upvotes: 4

Lukas Knuth
Lukas Knuth

Reputation: 25755

I don't think this is possible because a FileInputStream is simply a InputStream for Files. It does the job of getting an InputStream from the defined file for you, after that you're working with a normal InputStream.

Android already did this Job for you. So why do you need a FileInputStream?

Upvotes: 3

Related Questions