import java.net.HttpURLConnection; import java.net.URL; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class GetWebPageStatus { public static void main(String[] args) { final String SymbolsFilePath = "C:\\**\\StocksNeedRemove_Live.txt"; final String baseURL = "http://**/markets/stocks/"; BufferedReader SymbolsFile = null; String symbol; try { System.out.println("--------------"); System.out.println("SYMBOL\tSTATUS"); SymbolsFile = new BufferedReader(new FileReader(SymbolsFilePath)); symbol = SymbolsFile.readLine(); int Status; while (symbol != null) { Status = GetStatus(baseURL + symbol); if (Status != -1) { System.out.println(symbol.toUpperCase() + "\t" + Status); } else { System.out.println(symbol + "\tGet status error!"); } symbol = SymbolsFile.readLine(); } System.out.println("--------------"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (SymbolsFile != null) { // Close the file once all data has been read. try { SymbolsFile.close(); } catch (IOException ex) { System.out.println(ex.getMessage()); } } } // TODO Auto-generated method stub } public static int GetStatus(String url) { int Status = -1; try { URL Url = new URL(url); HttpURLConnection connection = (HttpURLConnection) Url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); Status = connection.getResponseCode(); connection.disconnect(); return Status; } catch (Exception e) { System.out.println(e.getMessage()); return Status; } } }