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
There is no real difference. FileInputStream extends InputStream , and so you can assign an InputStream object to be a FileInputStream object. In the end, it's the same object, so the same operations will happen. This behavior is called Polymorphism and is very important in Object-Oriented Programming.
To convert an InputStream Object int to a String using this method. Instantiate the Scanner class by passing your InputStream object as parameter. Read each line from this Scanner using the nextLine() method and append it to a StringBuffer object. Finally convert the StringBuffer to String using the toString() method.
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.
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).
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With