简体   繁体   English

无法从远程位置下载exe文件

[英]Unable to download the exe file from remote location

I am unable to download an exe file from server machine. 我无法从服务器计算机下载exe文件。

IE I can able to download a exe file from my location machine and save it in the disk, but not from the other server, but When I am trying to access it from the server machine it's not downloading, and giving an error like: IE浏览器可以从我的定位机器上下载一个exe文件并将其保存在磁盘上,但不能从其他服务器上保存,但是当我尝试从服务器机器上访问它时,它没有下载,并出现如下错误:

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

Below is my code: 下面是我的代码:

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

How do I solve the FileNotFoundException? 如何解决FileNotFoundException?

You can't open a URL using FileInputStream ! 您不能使用FileInputStream打开URL! You could use a URLConnection and obtain an InputStream from that; 您可以使用URLConnection并从中获取InputStream then you'd have to copy all the data from the InputStream and (presumably) save it to a local file. 那么您就必须从InputStream复制所有数据,并(大概)将其保存到本地文件中。

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();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM