将输入流转换为文件输入流?
我遇到了问题 - 我需要从 Android APK(例如 key.keystore)读取 SecretKey,对于我的应用程序,它必须作为 FileInputStream 读取,但从资产中我只能获取 inputStream。如何将inputStream转换为FileInputStream?或者有没有其他方法,如何从例如资源作为 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么你特别需要一个FileInputStream?一般来说,您不必关心InputStream的底层实现,您只需从中读取即可。也许您的实现应该与InputStream无关。
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.
我认为您指的是 AssetManager.open()返回一个输入流。无需将其“转换”为 FileInputStream,只需获取对 InputStream 的引用并使用它(如果需要,请将其包装在 BufferedInputStream 中)。
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).
我认为这是不可能的,因为 FileInputStream 只是文件的输入流。它会为您从定义的文件中获取输入流,然后您就可以使用普通的输入流了。
Android 已经为你完成了这项工作。那么为什么需要 FileInputStream 呢?
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?