我正在尝试使用 JAVA 解压缩文件,并且它正在编译没有任何错误。当我从我的工具中调用它时,并给出文件的绝对目标路径和源路径,例如:源:D:\data\test.zip 目标:D:\data\op\
我收到错误,例如拒绝访问(我有系统的管理员访问权限)
堆栈跟踪:
提取:test/New Text Document - Copy (2).txt java.io.FileNotFoundException: D:\Data\Op (Access is denied) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream。 (FileOutputStream.java:179) 在 java.io.FileOutputStream.(FileOutputStream.java:70)
下面是我正在调用的函数,我相信它与目的地有关,因为它可能不会提取到绝对路径,而是一些无法写入的临时文件夹。我在目的地尝试了一些组合,但最终没有工作。请指导我如何解决它。
public void unzip(String zipFilePath, String destDir, String flName) throws Exception
{
int BUFFER = 2048;//Buffer Size
try
{
File dir = new File(destDir);
// Throw Exception if output directory doesn't exist
if(!dir.exists())
{
//Print Message in Consol
System.out.println("No Destination Directory Exists for Unzip Operation.");
throw new Exception();
}
BufferedOutputStream dest = null;
BufferedInputStream is = null;
ZipEntry entry;
ZipFile zipfile = new ZipFile(zipFilePath);
Enumeration e = zipfile.entries();
while(e.hasMoreElements())
{
entry = (ZipEntry) e.nextElement();
System.out.println("Extracting: " +entry);
is = new BufferedInputStream (zipfile.getInputStream(entry));
int count;
byte data[] = new byte[BUFFER];
FileOutputStream fos = new FileOutputStream(destDir);
dest = new BufferedOutputStream(fos, BUFFER);
while ((count = is.read(data, 0, BUFFER)) != -1)
{
dest.write(data, 0, count);
}
//Close All Streams
dest.flush();
dest.close();
is.close();
}
}
catch(Exception e)
{
e.printStackTrace();
throw new Exception();
}
}