更新系统的文件下载程序正在崩溃



我目前正在用java编写一个应用程序,该应用程序将mods安装到minecraft中,并且更新程序/首次运行系统在尝试下载所需文件时崩溃,我得到了以下异常

java.io.IOException: Access is denied
    at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    at java.io.File.createNewFile(Unknown Source)
    at com.hachisoftware.mat.launcher.Util.getFileFromWeb(Util.java:43)
    at com.hachisoftware.mat.launcher.Main.setup(Main.java:22)
    at com.hachisoftware.mat.launcher.Main.main(Main.java:15)
java.io.FileNotFoundException: Gui.jar (Access is denied)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at com.hachisoftware.mat.launcher.Util.getFileFromWeb(Util.java:71)
    at com.hachisoftware.mat.launcher.Util.getFileFromWeb(Util.java:45)
    at com.hachisoftware.mat.launcher.Main.setup(Main.java:22)
    at com.hachisoftware.mat.launcher.Main.main(Main.java:15)
java.io.IOException: Access is denied
    at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    at java.io.File.createNewFile(Unknown Source)
    at com.hachisoftware.mat.launcher.Util.getFileFromWeb(Util.java:43)
    at com.hachisoftware.mat.launcher.Main.setup(Main.java:23)
    at com.hachisoftware.mat.launcher.Main.main(Main.java:15)
java.io.FileNotFoundException: IntelliMod.jar (Access is denied)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at com.hachisoftware.mat.launcher.Util.getFileFromWeb(Util.java:71)
    at com.hachisoftware.mat.launcher.Util.getFileFromWeb(Util.java:45)
    at com.hachisoftware.mat.launcher.Main.setup(Main.java:23)
    at com.hachisoftware.mat.launcher.Main.main(Main.java:15)

我正在使用以下代码下载

public static boolean getFileFromWeb(String location, String destination)
{
    String[] s = location.split("/");
    String s2 = s[s.length - 1];
    if(!"".equals(destination) && !(new File(destination)).exists())
        (new File(destination)).mkdir();
    File outFile = new File(destination, s2);
    if(!outFile.exists())
        try { outFile.createNewFile(); } catch(Exception e) { e.printStackTrace(); }
    return getFileFromWeb(outFile, location);
}
public static boolean getFileFromWeb(File outFile, String location)
{
    BufferedInputStream in = null;
    BufferedOutputStream out = null;
    try
    {
        URL url = new URL(location);
        URLConnection urlc = url.openConnection();
        urlc.setRequestProperty("User-Agent", "HS File Downloader(" + clientName + ")");
        in = new BufferedInputStream(urlc.getInputStream());
        out = new BufferedOutputStream(new FileOutputStream(outFile));
        byte[] dataBuffer = new byte[4096 * 1024];
        for(int line = in.read(dataBuffer); line != -1; line = in.read(dataBuffer))
        {
            out.write(dataBuffer, 0, line);
            out.flush();
        }
        in.close();
        out.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
        return false;
    }
    return true;
}

欢迎任何帮助或建议

异常清楚地表明

java.io.IOException: Access is denied
java.io.FileNotFoundException: Gui.jar (Access is denied)

请确保您的程序有权访问文件系统。

最新更新