Как решить проблему, что putNextEntry (ZipEntry) не принимает ZipParameters? - PullRequest
0 голосов
/ 01 апреля 2019

Когда я включаю fileName и zipParameter в putNextEntry():

ZipOutputStream.putNextEntry(fileName, zipParameter);

Показывает ошибку:

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

Ответы [ 2 ]

1 голос
/ 01 апреля 2019

Я надеюсь, что ваше 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 голосов
/ 01 апреля 2019

Вот подпись метода putNextEntry для java.util.zip.ZipOutputStream, которая принимает аргумент только 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
        }
       ....
...