Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用TrueZip和符号链接在存档中写入时出现的问题_Java_Unix_Symlink_Truezip - Fatal编程技术网

Java 使用TrueZip和符号链接在存档中写入时出现的问题

Java 使用TrueZip和符号链接在存档中写入时出现的问题,java,unix,symlink,truezip,Java,Unix,Symlink,Truezip,我使用TrueZip(V7.6.4)写入zip存档。我有一组文件夹,如下所示: > ls -l /home/remi drwxr-xr-x 2 remi remi 4096 sept. 10 16:49 testtz drwxr-xr-x 2 remi remi 4096 sept. 10 16:49 symlinktarget lrwxrwxrwx 1 remi remi 14 sept. 10 16:47 symlink -> symlinktarget/ >

我使用TrueZip(V7.6.4)写入zip存档。我有一组文件夹,如下所示:

> ls -l /home/remi
drwxr-xr-x  2 remi remi  4096 sept. 10 16:49 testtz
drwxr-xr-x  2 remi remi  4096 sept. 10 16:49 symlinktarget
lrwxrwxrwx  1 remi remi    14 sept. 10 16:47 symlink -> symlinktarget/
> ls -l /home/remi/testtz
lrwxrwxrwx 1 remi remi 25 sept. 10 16:47 symlink -> /home/remi/symlinktarget/
代码如下:

package com.tests.forstackoverflow.truezip;

import java.io.File;
import java.io.Writer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileWriter;
import de.schlichtherle.truezip.file.TVFS;
import de.schlichtherle.truezip.fs.FsSyncException;

public class TestTz
{
    Logger logger = LoggerFactory.getLogger(getClass());

    public void writeInArchive(String archiveName)
    {
        final File f = new TFile(new File(archiveName) + "/hello.txt");
        try (Writer writer = new TFileWriter(f))
        {
            writer.write("Hello World!\n");
        }
        catch(Exception e)
        {
            logger.error("Exception raised:", e);
        }
        try { TVFS.umount(); } catch(FsSyncException e) { logger.error("umount error", e); }
    }

    public static void main(String args[])
    {
        TestTz test = new TestTz();

        test.writeInArchive("/home/remi/testtz/hello.zip");

        test.writeInArchive("/home/remi/symlink/hello.zip");

        test.writeInArchive("/home/remi/testtz/symlink/hello2.zip");

    }
}
第一次调用
writeInachive
可以正常工作。随后的调用(给出了存档路径,其中最后一个目录是符号链接)引发以下异常:

sept. 10, 2014 4:49:55 PM com.tests.forstackoverflow.truezip.TestTz writeInArchive
Grave: Exception raised:
java.io.FileNotFoundException: /home/remi/symlink/hello.zip/hello.txt
    at de.schlichtherle.truezip.file.TFileOutputStream.newOutputStream(TFileOutputStream.java:147)
    at de.schlichtherle.truezip.file.TFileOutputStream.<init>(TFileOutputStream.java:116)
    at de.schlichtherle.truezip.file.TFileWriter.<init>(TFileWriter.java:42)
    at com.tests.forstackoverflow.truezip.TestTz.writeInArchive(TestTz.java:21)
    at com.tests.forstackoverflow.truezip.TestTz.main(TestTz.java:38)
Caused by: java.nio.file.FileAlreadyExistsException: /home/remi/symlink
    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:88)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
    at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:383)
    at java.nio.file.Files.createDirectory(Files.java:628)
    at java.nio.file.Files.createAndCheckIsDirectory(Files.java:732)
    at java.nio.file.Files.createDirectories(Files.java:681)
    at de.schlichtherle.truezip.fs.nio.file.FileOutputSocket.begin(FileOutputSocket.java:97)
    at de.schlichtherle.truezip.fs.nio.file.FileOutputSocket.newOutputStream(FileOutputSocket.java:211)
    at de.schlichtherle.truezip.fs.archive.zip.OptionOutputSocket.newOutputStream(OptionOutputSocket.java:48)
    at de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop(ZipDriver.java:589)
    at de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop0(ZipDriver.java:579)
    at de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop(ZipDriver.java:564)
    at de.schlichtherle.truezip.fs.FsTargetArchiveController.makeOutputArchive(FsTargetArchiveController.java:247)
    at de.schlichtherle.truezip.fs.FsTargetArchiveController.mount0(FsTargetArchiveController.java:182)
    at de.schlichtherle.truezip.fs.FsTargetArchiveController.mount(FsTargetArchiveController.java:155)
    at de.schlichtherle.truezip.fs.FsFileSystemArchiveController$ResetFileSystem.autoMount(FsFileSystemArchiveController.java:85)
    at de.schlichtherle.truezip.fs.FsFileSystemArchiveController.autoMount(FsFileSystemArchiveController.java:37)
    at de.schlichtherle.truezip.fs.FsBasicArchiveController$1Output.mknod(FsBasicArchiveController.java:273)
    at de.schlichtherle.truezip.fs.FsBasicArchiveController$1Output.newOutputStream(FsBasicArchiveController.java:233)
    at de.schlichtherle.truezip.fs.FsContextController$Output.newOutputStream(FsContextController.java:322)
    at de.schlichtherle.truezip.fs.FsResourceController$Output.newOutputStream(FsResourceController.java:273)
    at de.schlichtherle.truezip.socket.DelegatingOutputSocket.newOutputStream(DelegatingOutputSocket.java:57)
    at de.schlichtherle.truezip.fs.FsSyncController$Output.newOutputStream(FsSyncController.java:432)
    at de.schlichtherle.truezip.fs.FsLockController$Output$1NewOutputStream.call(FsLockController.java:509)
    at de.schlichtherle.truezip.fs.FsLockController$Output$1NewOutputStream.call(FsLockController.java:506)
    at de.schlichtherle.truezip.fs.FsLockController.locked(FsLockController.java:328)
    at de.schlichtherle.truezip.fs.FsLockController.writeLocked(FsLockController.java:268)
    at de.schlichtherle.truezip.fs.FsLockController$Output.newOutputStream(FsLockController.java:513)
    at de.schlichtherle.truezip.fs.FsFinalizeController$Output.newOutputStream(FsFinalizeController.java:209)
    at de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$1Output$NewOutputStream.call(FsFalsePositiveArchiveController.java:409)
    at de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$1Output$NewOutputStream.call(FsFalsePositiveArchiveController.java:402)
    at de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$TryChild.call(FsFalsePositiveArchiveController.java:507)
    at de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController.call(FsFalsePositiveArchiveController.java:104)
    at de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$1Output.newOutputStream(FsFalsePositiveArchiveController.java:399)
    at de.schlichtherle.truezip.file.TFileOutputStream.newOutputStream(TFileOutputStream.java:143)
    ... 4 more
2014年9月10日下午4:49:55 com.tests.forstackoverflow.truezip.TestTz writeInArchive
严重:提出的例外:
java.io.FileNotFoundException:/home/remi/symlink/hello.zip/hello.txt
位于de.schlichtherle.truezip.file.TFileOutputStream.newOutputStream(TFileOutputStream.java:147)
位于de.schlichtherle.truezip.file.TFileOutputStream。(TFileOutputStream.java:116)
位于de.schlichtherle.truezip.file.TFileWriter。(TFileWriter.java:42)
位于com.tests.forstackoverflow.truezip.TestTz.writeInachive(TestTz.java:21)
位于com.tests.forstackoverflow.truezip.TestTz.main(TestTz.java:38)
原因:java.nio.file.filealreadyexistException:/home/remi/symlink
位于sun.nio.fs.UnixException.translateToIOException(UnixException.java:88)
位于sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
位于sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
位于sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:383)
位于java.nio.file.Files.createDirectory(Files.java:628)
在java.nio.file.Files.createAndCheckIsDirectory(Files.java:732)
位于java.nio.file.Files.createDirectory(Files.java:681)
位于de.schlichtherle.truezip.fs.nio.file.FileOutputSocket.begin(FileOutputSocket.java:97)
位于de.schlichtherle.truezip.fs.nio.file.FileOutputSocket.newOutputStream(FileOutputSocket.java:211)
位于de.schlichtherle.truezip.fs.archive.zip.OptionOutputSocket.newOutputStream(OptionOutputSocket.java:48)
位于de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop(ZipDriver.java:589)
位于de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop0(ZipDriver.java:579)
位于de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop(ZipDriver.java:564)
位于de.schlichtherle.truezip.fs.fstargetachivecontroller.makeOutputArchive(fstargetachivecontroller.java:247)
位于de.schlichtherle.truezip.fs.fstargetachivecontroller.mount0(fstargetachivecontroller.java:182)
位于de.schlichtherle.truezip.fs.fstargetachivecontroller.mount(fstargetachivecontroller.java:155)
位于de.schlichtherle.truezip.fs.FsFileSystemArchiveController$ResetFileSystem.autoMount(FsFileSystemArchiveController.java:85)
位于de.schlichtherle.truezip.fs.FsFileSystemArchiveController.autoMount(FsFileSystemArchiveController.java:37)
位于de.schlichtherle.truezip.fs.FsBasicArchiveController$1Output.mknod(FsBasicArchiveController.java:273)
位于de.schlichtherle.truezip.fs.FsBasicArchiveController$1Output.newOutputStream(FsBasicArchiveController.java:233)
位于de.schlichtherle.truezip.fs.FsContextController$Output.newOutputStream(FsContextController.java:322)
位于de.schlichtherle.truezip.fs.FsResourceController$Output.newOutputStream(FsResourceController.java:273)
位于de.schlichtherle.truezip.socket.DelegatingOutputSocket.newOutputStream(DelegatingOutputSocket.java:57)
位于de.schlichtherle.truezip.fs.FsSyncController$Output.newOutputStream(FsSyncController.java:432)
位于de.schlichtherle.truezip.fs.FsLockController$Output$1NewOutputStream.call(FsLockController.java:509)
位于de.schlichtherle.truezip.fs.FsLockController$Output$1NewOutputStream.call(FsLockController.java:506)
位于de.schlichtherle.truezip.fs.FsLockController.locked(FsLockController.java:328)
位于de.schlichtherle.truezip.fs.FsLockController.writeLocked(FsLockController.java:268)
位于de.schlichtherle.truezip.fs.FsLockController$Output.newOutputStream(FsLockController.java:513)
位于de.schlichtherle.truezip.fs.FsFinalizeController$Output.newOutputStream(FsFinalizeController.java:209)
位于de.schlichtherle.truezip.fs.fsFalsePositiverChiveController$1输出$NewOutputStream.call(fsFalsePositiverChiveController.java:409)
位于de.schlichtherle.truezip.fs.fsFalsePositiverChiveController$1输出$NewOutputStream.call(fsFalsePositiverChiveController.java:402)
在de.schlichtherle.truezip.fs.fsFalsePositiverAchiveController$TryChild.call(fsFalsePositiverAchiveController.java:507)
在de.schlichtherle.truezip.fs.fsFalsePositiverChiveController.call(fsFalsePositiverChiveController.java:104)
位于de.schlichtherle.truezip.fs.fsFalsePositiverChiveController$1输出.newOutputStream(fsFalsePositiverChiveController.java:399)
位于de.schlichtherle.truezip.file.TFileOutputStream.newOutputStream(TFileOutputStream.java:143)
... 4更多

是否将TrueZip添加到现有项目中?如果是这样,您可能需要在项目中包含Truezip驱动程序zip依赖项。您不需要将其导入到项目中,但需要将依赖项jar内置到项目中。如果您没有使用maven,请使用任何必须包含它的构建过程。

请将TrueZIP和JDK更新为最新版本,然后重复此测试。我怀疑这可能会解决这个问题。我刚刚尝试使用TrueZip 7.7.6和最新的JDK7,但错误仍然存在。你是说我应该使用JDK8/9吗?