Hi,
I am trying to download a file from a HTTPS URL. I need to do it using JDK1.3.1 which means that I do not have javax.net.ssl package.
Given below is the code I have currently. It does not throw me any exception and downloads the file but I only get 0 bytes.
Please help!
private static boolean downloadFile(String source, String dest)
{
byte[] baBuffer = new byte[1024];
inti;
File destFile = new File(dest);
// if dest file already exists, return
if(destFile.exists())
{
return true;
}
try
{
java.net.URL url = new java.net.URL("https://" + source);
URLConnection urlConnection = url.openConnection();
urlConnection.setUseCaches(false);
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();
urlConnection.getOutputStream().flush();
urlConnection.getOutputStream().close();
DataInputStream di = new DataInputStream(urlConnection.getInputStream());
FileOutputStream fos = new FileOutputStream(destFile);
while((i = di.read(baBuffer)) != -1)
{
fos.write(baBuffer, 0, i);
}
fos.close();
return true;
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}