-3

当我包括fileNamezipParameterputNextEntry()

ZipOutputStream.putNextEntry(fileName, zipParameter);

它显示一个错误:

The method putNextEntry(ZipEntry) in the type ZipOutputStream is not applicable for the arguments (String, ZipParameters).
4

2 回答 2

1

我希望你的文件名没有被声明为字符串。它应该是FileOutputStream作为第一个参数,它应该得到File

File zipFile = new File("file.txt");
ZipOutputStream zos = new ZipOutputStream( new FileOutputStream(zipFile));
try
{
 ZipEntry entry = new ZipEntry("myFile.txt"); // put file inside 
 zos.putNextEntry(entry);
} catch (FileNotFoundException e)
{
 e.printStackTrace();
} catch (IOException e)
{
 e.printStackTrace();
} finally
{
 zos.closeEntry();
 zos.close();
}

试试看,可能有帮助

于 2019-04-01T04:23:59.967 回答
0

这是 java.util.zip.ZipOutputStream 的 putNextEntry 的方法签名,它只接受参数ZipEntry

 /**
     * Begins writing a new ZIP file entry and positions the stream to the
     * start of the entry data. Closes the current entry if still active.
     * The default compression method will be used if no compression method
     * was specified for the entry, and the current time will be used if
     * the entry has no set modification time.
     * @param e the ZIP entry to be written
     * @exception ZipException if a ZIP format error has occurred
     * @exception IOException if an I/O error has occurred
     */

    public void putNextEntry(ZipEntry e) throws IOException {
        ensureOpen();
        if (current != null) {
            closeEntry();       // close previous entry
        }
       ....
于 2019-04-01T04:55:10.547 回答