Foros de discusión

File reading is not happening through the InputStream

Logu R, modificado hace 7 años.

File reading is not happening through the InputStream

New Member Mensajes: 10 Fecha de incorporación: 15/05/15 Mensajes recientes
The file reading is not happening through the Input Stream, especially while downloading the file from https url.

Able to pass the authentication, by using the below statement.
con.setRequestProperty ("Authorization", "Basic " + loginPassword);

Please find the code below
url = new URL(fileURL);
con = url.openConnection();
con.setRequestProperty ("Authorization", "Basic " + loginPassword);
InputStream is = con.getInputStream();
OutputStream os = new FileOutputStream(saveDir);

while ((i = is.read()) != -1) {
os.write(BUFFER_SIZE,0,i);
//System.out.println("file downloaded");
}

Can any one please assist on this.