Obtenir la source d'une URL
Bonjour,
J'avais besoin pour une application d'un système très simple pour obtenir la source d'une URL. J'ai donc un peu bidouillé du code trouvé sur internet, ce qui m'a donné ça :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
String get_source(String url)
{
try {
URL textUrl = new URL(url);
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
return stringText;
}
catch (MalformedURLException e)
{
e.printStackTrace();
return e.toString();
}
catch (IOException e) {
e.printStackTrace();
return e.toString();
}
} |
Malheureusement, l'application plante quand je la lance en utilisant ça.
Quelqu'un arriverait-il à m'indiquer la ou les erreurs, ou une solution plus simple ?
Merci d'avance,
7804j