0

I am unable to download an exe file from server machine.

I.E. 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:

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?

Quaternion
  • 10,380
  • 6
  • 51
  • 102
user1216228
  • 383
  • 1
  • 4
  • 10

2 Answers2

0

You can't open a URL using FileInputStream! You could use a URLConnection and obtain an InputStream from that; then you'd have to copy all the data from the InputStream and (presumably) save it to a local file.

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
-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();
    }
}
Churk
  • 4,556
  • 5
  • 22
  • 37
  • The `Reader` classes here would mangle the `*.exe` file, which is binary, not character data. You must use the `InputStream` from the `URL` directly. – Ernest Friedman-Hill Feb 28 '12 at 14:21
  • I think u need to read a little before u give your answer: http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html – Churk Feb 28 '12 at 14:22
  • Your code is appropriate for reading an HTML file (for example,) but not for downloading a `*.exe` file, which is what the question is about. If you use this code for binary data like a `*.exe`, the file will be corrupted. – Ernest Friedman-Hill Feb 28 '12 at 14:47
  • Here is the a question asked easier of getting byte throw a URL: http://stackoverflow.com/questions/2295221/java-net-url-read-stream-to-byte – Churk Feb 28 '12 at 15:27