I currently writing a app in java that installs mods into minecraft and the updater/first time run system is crashing when it trys to download the needed files, I'm getting the following exception
我目前在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)
I'm using the following code for the downloading
我正在使用以下代码进行下载
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;
}
Any help or advice is welcome
欢迎任何帮助或建议
1 个解决方案
#1
0
Exception clearly says
例外明确说明
java.io.IOException: Access is denied
java.io.FileNotFoundException: \Gui.jar (Access is denied)
Make sure your program has rights to access file system.
确保您的程序有权访问文件系统。
#1
0
Exception clearly says
例外明确说明
java.io.IOException: Access is denied
java.io.FileNotFoundException: \Gui.jar (Access is denied)
Make sure your program has rights to access file system.
确保您的程序有权访问文件系统。