I am trying to download the following url as pdf file in local folder.
http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=1498781&tag=1
so far what i have tried is:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class DownloadPDF {
public DownloadPDF () {}
public static String download (String link, String i) {
String save = null;
try{
String file = link;
URL url = new URL(file);
InputStream in = url.openStream();
save = "local_folder/name.pdf";
FileOutputStream fos = new FileOutputStream(new File(save));
int length = -1;
byte[] buffer = new byte[1024];
while ((length = in.read(buffer)) > -1) {
fos.write(buffer, 0, length);
}
fos.close();
in.close();
System.out.println("file is downloaded");
} catch (IOException e) {
e.printStackTrace();
}
return save;
}
}
This works for:
http://ongambling.org/wp-content/uploads/2011/02/binde-2005-jgs-postprint.pdf
but does not work for the first url given above? is there any other suggestion?