0
我目前正在編寫一個應用程序在Java中安裝mods到我的世界和更新/第一次運行系統崩潰時,它試圖下載所需的文件,我得到以下異常文件下載器更新系統崩潰
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;
}
任何幫助或建議,歡迎
我知道,但它工作得 之前,它的工作原理,如果我做的: 'Util.getFileFromWeb(「http://mat.hachisoftware.com/engine/Gui.jar」,「庫」);' 'Util.getFileFromWeb(「http://mat.hachisoftware.com/engine/IntelliMod.jar」,「libs」);' – 2012-04-02 09:30:02
但不是 'Util.getFileFromWeb(「http://mat.hachisoftware.com/engine /Gui.jar「,」「);' 'Util.getFileFromWeb(」http://mat.hachisoftware.com/engine/IntelliMod.jar「,」「);' – 2012-04-02 09:31:25
我改變了我的代碼,現在正在工作,我正在將文件下載到啓動程序所在的文件夾中,我已將其更改爲下載到子文件夾 – 2012-04-02 09:35:04