如何解决putNextEntry(ZipEntry)不接受ZipParameters的问题?

问题描述 投票:-3回答:2

当我在fileName中包括zipParameterputNextEntry()时:

ZipOutputStream.putNextEntry(fileName, zipParameter);

它显示一个错误:

The method putNextEntry(ZipEntry) in the type ZipOutputStream is not applicable for the arguments (String, ZipParameters).
java zipoutputstream zip4j
2个回答
1
投票

我希望你的fileName没有声明为String。它应该是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();
}

尝试一下,它可能有所帮助


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
        }
       ....
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.