Det kræver ikke ret meget Java kode at hente med HTTP.
Dette kode hnter fra
http://www.eksperten.dk/ og gemmer som en
fil z.z:
import java.net.*;
import java.io.*;
public class HttpGet {
public static void main(String[] args) {
try {
URL url = new URL("
http://www.eksperten.dk/");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.connect();
if(con.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream is = con.getInputStream();
OutputStream os = new FileOutputStream("z.z");
byte[] b = new byte[1000];
int n;
while((n = is.read(b)) >= 0) {
os.write(b,0,n);
}
os.close();
is.close();
}
con.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Det vil også virke med XML.