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
| class GetURL {
public static void main (String [] argv) {
StringBuffer buff = new StringBuffer();
try {
URL url = new URL ("http://www.academie-francaise.fr/dictionnaire/index.html");
URLConnection uc = url.openConnection();
// On crée un flot d'entrée
(*)DataInputStream entree = new DataInputStream (new BufferedInputStream (uc.getInputStream()));
readPage(entree,buff);
} catch (Exception e) { e.printStackTrace(); }
// On récupère le document
System.out.println("Contenu du document: "+buff );
}
public static void readPage(InputStream in,StringBuffer buf){
int b = 0;
try {
while ((b = in.read()) != -1) {
buf.append((char) b);
}
} catch (IOException e) {
e.printStackTrace();
}
}
} |
Partager