文件夹是文件未压缩
Folder are file not zipping
我已经实现了压缩文件夹或文件然后下载并将其保存到内存中。
我的问题是,下载没有任何错误,但我没有收到 Zip 文件,如果我点击下载的文件,它会显示:
Can't show
或
Can't display message.
我的代码:
String fileName = tvtitle.getText().toString();
String fileExtension = tvtype.getText().toString();
File imageDirectory = new File(Path);
imageDirectory.mkdirs();
int fileLength = connection.getContentLength();
String _path = Path;
input = connection.getInputStream();
File outputFile = new File(_path, fileName + fileExtension);
FileOutputStream fos = new FileOutputStream(outputFile);
ZipOutputStream zos = new ZipOutputStream(fos);
File srcFile = new File(input.toString());
byte[] buffer = new byte[1024];
zos.putNextEntry(new ZipEntry(srcFile.getName()));
int length;
while ((length = input.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
input.close();
zos.close();
就是不知道这个变量的类型是什么"input"
我认为您应该将 FileInputStream(读取源文件)与 FileOutputStream(设置为 destination/zip 文件)配对。
这行代码:
File outputFile = new File(_path, fileName + fileExtension);
你的输出一定是 .zip 文件吧?
所以,应该是:
File outputFile = new File(_path, fileName + ".zip");
或类似的东西
而且会是这样
String fileName = tvtitle.getText().toString();
String fileExtension = tvtype.getText().toString();
File imageDirectory = new File(Path);
FileInputStream fis = new FileInputStream(imageDirectory);
ZipEntry zipEntry = new ZipEntry(fileName);
FileOutputStream fos = new FileOutputStream("test.zip");
ZipOutputStream zos = new ZipOutputStream(fos);
zos.putNextEntry(zipEntry);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zos.write(bytes, 0, length);
}
zos.closeEntry();
fis.close();
zos.close();
fos.close();
我已经实现了压缩文件夹或文件然后下载并将其保存到内存中。 我的问题是,下载没有任何错误,但我没有收到 Zip 文件,如果我点击下载的文件,它会显示:
Can't show
或
Can't display message.
我的代码:
String fileName = tvtitle.getText().toString();
String fileExtension = tvtype.getText().toString();
File imageDirectory = new File(Path);
imageDirectory.mkdirs();
int fileLength = connection.getContentLength();
String _path = Path;
input = connection.getInputStream();
File outputFile = new File(_path, fileName + fileExtension);
FileOutputStream fos = new FileOutputStream(outputFile);
ZipOutputStream zos = new ZipOutputStream(fos);
File srcFile = new File(input.toString());
byte[] buffer = new byte[1024];
zos.putNextEntry(new ZipEntry(srcFile.getName()));
int length;
while ((length = input.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
input.close();
zos.close();
就是不知道这个变量的类型是什么"input"
我认为您应该将 FileInputStream(读取源文件)与 FileOutputStream(设置为 destination/zip 文件)配对。
这行代码:
File outputFile = new File(_path, fileName + fileExtension);
你的输出一定是 .zip 文件吧? 所以,应该是:
File outputFile = new File(_path, fileName + ".zip");
或类似的东西
而且会是这样
String fileName = tvtitle.getText().toString();
String fileExtension = tvtype.getText().toString();
File imageDirectory = new File(Path);
FileInputStream fis = new FileInputStream(imageDirectory);
ZipEntry zipEntry = new ZipEntry(fileName);
FileOutputStream fos = new FileOutputStream("test.zip");
ZipOutputStream zos = new ZipOutputStream(fos);
zos.putNextEntry(zipEntry);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zos.write(bytes, 0, length);
}
zos.closeEntry();
fis.close();
zos.close();
fos.close();