im trying here at first check, if the file on URL exists and then if it exists download it. But it throws me
Exception in thread "main" sun.net.ftp.FtpProtocolException: Welcome message: 421 Too many connections (2) from this IP
If i know, i always close the connection, but anyway it crashes
private boolean exists(String URLName) throws MalformedURLException, IOException {
boolean result = false;
URL url = new URL(URLName);
input = url.openStream();
input.close();
result = true;
return result;
}
private void downloadTheFile(String path, String name) throws MalformedURLException, IOException {
input.close();
input = new URL(path).openStream();
try {
OutputStream out = new FileOutputStream(name + ".pdf");
byte buf[] = new byte[4096];
for (int n = input.read(buf); n > 0; n = input.read(buf)) {
out.write(buf, 0, n);
}
} finally {
out.close();
input.close();
}
}
could anyone help me please?