aspose file tools*
The moose likes I/O and Streams and the fly likes Download a file from a https: website Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Download a file from a https: website" Watch "Download a file from a https: website" New topic
Author

Download a file from a https: website

Quang Pham
Ranch Hand

Joined: Nov 29, 2005
Posts: 47
Hi
Can some one show me how to write a java program to download a file from a secure server https?
url=https://www.fededirectory.frb.org/FedACHdir.txt
Currently I am able to download file from http but got certificate issue when trying to download from https.
Here is the code:
-----------
public static void main(String args[]) throws IOException {
java.io.BufferedInputStream in =
new java.io.BufferedInputStream(
new java
.net
.URL("https://www.fededirectory.frb.org/FedACHdir.txt").openStream());
java.io.FileOutputStream fos =new java.io.FileOutputStream("c:/bankInfo.txt");
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
byte[] data = new byte[1024];
int x = 0;
while ((x = in.read(data, 0, 1024)) >= 0) {
bout.write(data, 0, x);
}
bout.close();
in.close();
System.out.println("File Downloaded");
}
-----------
Thanks
 
 
subject: Download a file from a https: website