Ril*_*eyE 1 java encoding android archive
作为免责声明,我已经看过这篇文章以及链接到它的帖子.
我有一个托管在服务器上的文件,该文件是n归档文件,我试图使用此方法取消归档.当文件预先下载到设备并且我在我的应用程序中打开并取消归档它时,通过intent-filterfrom Downloads,没有任何问题.但是,当我从我的应用程序中的服务器下载它,然后尝试解压缩它,我在这一行的标题中得到错误:
ZipFile zipfile = new ZipFile(archive);
Run Code Online (Sandbox Code Playgroud)
哪里archive是一个File指向存档文件我下载.我用来下载档案的代码如下:
String urlPath = parameters[0], localPath = parameters[1];
try
{
URL url = new URL(urlPath);
URLConnection connection = url.openConnection();
connection.addRequestProperty("Accept-Encoding", "gzip");
connection.connect();
int fileLength = connection.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new BufferedOutputStream(new FileOutputStream(localPath));
byte data[] = new byte[1024];
long total = 0;
int count;
while((count = input.read(data)) != -1)
{
total += count;
publishProgress((int)total * 100 / fileLength);
output.write(data);
}
output.flush();
output.close();
input.close();
Run Code Online (Sandbox Code Playgroud)
我最近添加了编码类型 - 按照我在顶部引用的帖子,但我仍然得到相同的错误.任何帮助都会很棒.
只是为了澄清:
java.util.zip.ZipException: Central Directory Entry not found我最好的猜测是这是我的下载问题.然而,话虽如此,我不知道我做错了什么.
您没有正确复制下载.你必须使用
output.write(data, 0, count);
Run Code Online (Sandbox Code Playgroud)
否则,您正在将任意垃圾写入文件.