将输入流转换为文件输入流?

发布于 2024-11-03 00:30:00 字数 204 浏览 0 评论 0原文

我遇到了问题 - 我需要从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゝ杯具 2024-11-10 00:30:00

为什么你特别需要一个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.

一绘本一梦想 2024-11-10 00:30:00

我认为您指的是 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).

醉生梦死 2024-11-10 00:30:00

我认为这是不可能的,因为 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文