1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
public static void main(String s[]) {
String code = "0";
final String urlP = "http://toto.fr/cgi-bin/exterieurs/index.php?action=getpdf&num="+code;
URL url = null;
try {
url = new URL(urlP);
}
catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (url == null) {
return;
}
BufferedInputStream in = null;
try {
in = new BufferedInputStream (url.openStream());
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (in == null) {
return;
}
final File f = new File("D:\\Demande"+code+".pdf");
OutputStream out = null;
try {
out = new FileOutputStream(f);
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
if (out == null) {
closeStream(in);
return;
}
}
final int BUFF_LEN = 4096;
final byte[] buffer = new byte[BUFF_LEN];
int read;
try {
while ((read = in.read(buffer, 0, BUFF_LEN)) != -1) {
out.write(buffer, 0, read);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
closeStream(in);
closeStream(out);
}
} |
Partager