vendredi 2 décembre 2016

GetURLsource method gives in some cases erros java

I have developed this piece of code to get the url source code of a web page. Yet this method gives sometimes fails, and it is unable to 'grab' the source code of a page.

 private static String[] getUrlSource(String url) throws IOException {
    List<String> myList = new ArrayList<String>();
    URL site = new URL(url);
    BufferedReader in = new BufferedReader(new InputStreamReader(
                site.openStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null)
        myList.add(inputLine);
    in.close();

    String[] arr = myList.toArray(new String[myList.size()]);
    return arr;
}




Aucun commentaire:

Enregistrer un commentaire