• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Download a file from a https: website

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic