Como eu posso fazer o download de um arquivo contido em uma URL ex: “http://meudominio.com/meuarquivo.txt”
Obrigado.
Como eu posso fazer o download de um arquivo contido em uma URL ex: “http://meudominio.com/meuarquivo.txt”
Obrigado.
use o httpclient da apache
Ou pode sempre ir pela maneira dificil…
http://www.hr.utah.edu/blog/?p=4
public class JavaNetUrlExample {
public static void main(String[] args){
String webFile = "http://www.hr.utah.edu/";
try {
URL url = new URL(webFile);
InputStream in = url.openStream();
byte[] buf = new byte[1024];
int len;
while( (len = in.read(buf)) > 0 ){
for(int i = 0; i < len; i++){
System.out.print((char)buf[i]);
}
}
//close the stream
in.close();
}catch (MalformedURLException e){
//TODO
}catch (IOException e){
//TODO:FileNotFoundException caught here
}finally{
//TODO
}
}
}