File size: 1,012 Bytes
c574d3a |
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 |
package serveur.src.modeles;
import java.io.*;
import java.net.*;
public class Utils {
public static int randomInt(int min, int max) {
return (int) (Math.random() * ((max - min) + 1)) + min;
}
public static String getUrlContents(String theUrl) {
StringBuilder res = new StringBuilder();
try {
URL url = new URL(theUrl);
// Se connecte à l'URL
URLConnection con = url.openConnection();
// Récupère le contenu de l'url via des readers
BufferedReader liseur = new BufferedReader(new InputStreamReader(con.getInputStream()));
String ligne;
// Tant que l'url récupérée contient une ligne
while ((ligne = liseur.readLine()) != null) {
// On l'ajoute au résultat
res.append(ligne + "\n");
}
liseur.close();
} catch (Exception e) {
e.printStackTrace();
}
return res.toString();
}
}
|