如何从一个文件夹中的一个zip文件这是由ACTION_OPEN_DOCUMENT_TREE意图选择读? [英] how to read from a zipfile in a folder which was selected by the ACTION_OPEN_DOCUMENT_TREE Intent?

查看:842
本文介绍了如何从一个文件夹中的一个zip文件这是由ACTION_OPEN_DOCUMENT_TREE意图选择读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从一个文件夹中的一个zip文件这是由ACTION_OPEN_DOCUMENT_TREE意图选择读?

我的应用程序让用户选择通过ACTION_OPEN_DOCUMENT_TREE意向的文件夹。
在该文件夹,我将有一个zip文件具有特定名称。
目标是读取压缩文件与java.util.zip.ZipFile中。

我如何实例化一个ZipFile中从提供的URI这个特定Zipfilename(Folderinfo)中的onActivityResult?

 保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
    乌里treeUri = data.getData();
    字符串SPATH = treeUri.getPath();    java.util.zip.ZipFile中myzip =新java.util.zip.ZipFile中(mypath中); < - 构造函数期待文件名或路径为String。 HOWTO与开放的我们处理这个问题?


解决方案

  

我如何实例化一个ZipFile中从提供的URI这个特定Zipfilename(Folderinfo)中的onActivityResult?


您不能,因为没有文件,的ZipFile 需要的文件。你只能得到一个的InputStream ,使用 openInputStream() ContentResolver的,并且只有如果你得到一个乌里来,你正在寻找一个特定的文件。

您的选择似乎是:


  • 使用 ZipInputStream ,它可以换一个的InputStream


  • 找一些接受一个的InputStream 作为输入并为您提供了一个更好的API的第三方库


  • 在ZIP flie复制到内部存储应用的部分,并使用其内容读的ZipFile


how to read from a zipfile in a folder which was selected by the ACTION_OPEN_DOCUMENT_TREE Intent ?

My app let the user choose a folder through the ACTION_OPEN_DOCUMENT_TREE Intent. In that folder i will have a Zipfile with a specific name. Goal is to read that Zipfile with java.util.zip.ZipFile.

How do I instantiate a ZipFile with this specific Zipfilename from the provided URI (Folderinfo) in onActivityResult ?

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Uri treeUri = data.getData();
    String sPath=treeUri.getPath();

    java.util.zip.ZipFile myzip=new java.util.zip.ZipFile("mypath"); <-- Constructor expects File or Path as String. Howto handle this with the Uri ?

解决方案

How do I instantiate a ZipFile with this specific Zipfilename from the provided URI (Folderinfo) in onActivityResult ?

You can't, as there is no file, and ZipFile needs a file. You can only get an InputStream, using openInputStream() on a ContentResolver, and that only if you get a Uri to that specific file that you are looking for.

Your options appear to be:

  • Use ZipInputStream, which can wrap an InputStream

  • Find some third-party library that accepts an InputStream as input and gives you a better API

  • Copy the ZIP flie to your app's portion of internal storage and read its contents using ZipFile

这篇关于如何从一个文件夹中的一个zip文件这是由ACTION_OPEN_DOCUMENT_TREE意图选择读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆