1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| int offs = 0, lus = 0;
System.setProperty("http.agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
Scanner input = new Scanner(System.in); //Récupération de l'adresse hote à analyser
hote = input.next();
out.println("Connexion à "+hote+"...");
URL url = new URL("http", hote, "");
URLConnection connexion = url.openConnection(); //Ouverture de la connexion
weight = connexion.getContentLength(); //Récupération du poids en octet du contenu
type = connexion.getContentType(); //Récupération du type de données
// Récupération du contenu
InputStream Content = connexion.getInputStream();
byte fileContent[] = new byte[weight];
while (lus < weight)
{
int octetsLus = Content.read(fileContent, offs, weight - offs);
offs += octetsLus;
lus += octetsLus;
}
String content = new String(fileContent);
Content.close(); //Fermeture de la connexion |