I have a ArrayList containing list of websites in this format:-
- google.com
- facebook.com
- youtube.com
- yahoo.com
- wikipedia.org
t.co
And I have to read html text from all the links. But some links are creating problem like (t.co) and other are working fine.
Code:-
try { String line="t.co"; String[] Add_words = line.split("[//:.]"); if (Add_words[0].contains("http")) { } else if (Add_words[0].contains("www")) line = "http://" + line; else if (!Add_words[0].contains("http") && !Add_words[0].contains("www")) line = "http://www." + line; URL url = new URL(line); URLConnection urlConnection = url.openConnection(); HttpURLConnection connection = null; if(urlConnection instanceof HttpURLConnection) { connection = (HttpURLConnection) urlConnection; } else { System.out.println("Please enter an HTTP URL."); return; } BufferedReader in = new BufferedReader( new InputStreamReader(connection.getInputStream())); String urlString = ""; String current; while((current = in.readLine()) != null) { urlString += current+"\n"; } System.out.println(urlString); }catch(IOException e) { e.printStackTrace(); } And I'm getting the error with the last link `t.co`error:-
java.io.FileNotFoundException: http://www.t.co at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1834) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439) at com.test.code.Main.main(Main.java:109)What i need is, I have list of link in above format and my code should access all the link, whatever the link format will be.