I'm currently trying to create a Java
program that will unzip a folder into a certain folder within the Program Files
Folder.
I'm using the 3rd party library Zip4j
to unzip the folder. the following is the code i'm using.
String source = "C:\\Users\\chris\\Desktop\\New folder.zip";
String destination = "C:\\Program Files (x86)\\Test Folder";
String password = "password";
try {
ZipFile zipFile = new ZipFile(source);
if (zipFile.isEncrypted()) {
zipFile.setPassword(password);
}
zipFile.extractAll(destination);
} catch (ZipException e) {
e.printStackTrace();
}
it works perfectly if I'm trying to unzip to a normal folder on the desktop. but once i try to unzip it to the program files i get the following Exception java.io.FileNotFoundException
.
I assume that my program needs admin rights to be able access the folder within the Program Files
folder. Does anyone know how to do this?
Error log:
Caused by: java.io.FileNotFoundException: C:\Program Files (x86)\Test Folder\New folder\New Text Document.txt (The system cannot find the path specified) at java.io.FileOutputStream.open0(Native Method) at java.io.FileOutputStream.open(FileOutputStream.java:270) at java.io.FileOutputStream.<init>(FileOutputStream.java:213) at java.io.FileOutputStream.<init>(FileOutputStream.java:162) at net.lingala.zip4j.unzip.UnzipEngine.getOutputStream(UnzipEngine.java:432) ... 7 more