2012-02-28 34 views
0

我無法從服務器機器下載exe文件。無法從遠程位置下載exe文件

I.E.我可以從我的位置機器下載一個EXE文件並將其保存在磁盤中,但不能從其他服務器上下載,但是當我試圖從服務器機器訪問它時,它不會下載,並且出現如下錯誤:

java.io.FileNotFoundException: http:\10.128.10.60\home\test\filexilla.exe(The filename, directory name, or volume label syntax is incorrect) 

下面是我的代碼:

fileInputStream = new FileInputStream(new File("E:\\Sunnywellshare\\perl\\filezilla.exe")) 
//this code is working fine 

fileInputStream = new FileInputStream(new File("http://10.127.10.10/test/filezilla.exe")); 
//this code is from remote location.and throwing error 

如何解決FileNotFoundException異常?

回答

0

您無法使用FileInputStream打開網址!您可以使用URLConnection並從中獲得InputStream;那麼你必須複製InputStream的所有數據,並且(大概)將其保存到本地文件中。

-1
import java.net.*; 
import java.io.*; 

public class URLReader { 
    public static void main(String[] args) throws Exception { 
    URL oracle = new URL("http://www.oracle.com/"); 
    BufferedReader in = new BufferedReader(
     new InputStreamReader(
     oracle.openStream())); 

    String inputLine; 

    while ((inputLine = in.readLine()) != null) 
     System.out.println(inputLine); 

    in.close(); 
    } 
} 
+0

這裏的'Reader'類會破壞'* .exe'文件,它是二進制文件,而不是字符數據。您必須直接使用URL中的'InputStream'。 – 2012-02-28 14:21:24

+0

我想你需要閱讀一點之前,你給你的答案:http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html – Churk 2012-02-28 14:22:15

+0

你的代碼適合閱讀一個HTML文件(例如, ),但不能下載一個'* .exe'文件,這就是問題所在。如果您使用此代碼來處理二進制數據(如* .exe),則該文件將被損壞。 – 2012-02-28 14:47:59