I'm using TrueZip to create archives. It seems it regards the path D:\
as a system root folder and prevents me from creating files there. My os and all programs are as per default located at C:
. The drive D:\
contains personal data (documents, pictures, videos, whatever).
How can I create archives at the root of my drive?
The code I'm using to create archives:
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileOutputStream;
import de.schlichtherle.truezip.zip.ZipEntry;
import de.schlichtherle.truezip.zip.ZipOutputStream;
import javax.swing.*;
import java.io.*;
public class MainClass {
public static void main(String[] args) throws IOException {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Please select the target folder.");
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
JFrame applicationFrame = new JFrame();
if (chooser.showSaveDialog(applicationFrame) != JFileChooser.APPROVE_OPTION)
return;
File selectedFile = chooser.getSelectedFile();
TFile archiveFile = new TFile(selectedFile + ".zip");
System.out.println("Selected file: " + archiveFile.getAbsolutePath());
ZipOutputStream zipOutputStream = new ZipOutputStream(new TFileOutputStream(archiveFile));
File folderToZip = new File("D:/filesToZip");
File[] files = folderToZip.listFiles();
for (File file : files) {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
int avail = bis.available();
byte[] buffer = new byte[avail];
if (avail > 0) {
bis.read(buffer, 0, avail);
}
bis.close();
ZipEntry zipEntry = new ZipEntry(file.getName());
zipOutputStream.putNextEntry(zipEntry);
zipOutputStream.write(buffer, 0, buffer.length);
zipOutputStream.closeEntry();
}
zipOutputStream.close();
System.exit(0);
}
}
The error message I'm getting:
Selected file: D:\test.zip
Exception in thread "main" java.io.FileNotFoundException: D:\test.zip
at de.schlichtherle.truezip.file.TFileOutputStream.newOutputStream(TFileOutputStream.java:147)
at de.schlichtherle.truezip.file.TFileOutputStream.<init>(TFileOutputStream.java:116)
at MainClass.main(MainClass.java:21)
Caused by: de.schlichtherle.truezip.fs.FsArchiveFileSystemException: <file system root> (only files can get replaced)
at de.schlichtherle.truezip.fs.FsArchiveFileSystem.mknod(FsArchiveFileSystem.java:379)
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:283)
at de.schlichtherle.truezip.socket.DelegatingOutputSocket.newOutputStream(DelegatingOutputSocket.java:57)
at de.schlichtherle.truezip.fs.FsSyncController$Output.newOutputStream(FsSyncController.java:454)
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)
... 2 more