常用怕找不到資料,故做筆記一下

URL u = null;
InputStream in = null;
InputStreamReader r = null;
BufferedReader br = null;
String message = null;
List<String> data = new ArrayList<String>();

try {
   String xxx = "http://tw.yahoo.com";
   u = new URL(xxx);
   in = u.openStream();
   r = new InputStreamReader(in, "UTF-8");
   br = new BufferedReader(r);
   while ((message = br.readLine()) != null) {
      System.out.println(message);
   }

} catch (Exception e) {
   e.getStackTrace();
   System.out.println(e.getMessage());
} finally {
   try {
      u = null;
      in.close();
      r.close();
      br.close();
   } catch (Exception e) {

   }
}

Will(小威) 發表在 痞客邦 PIXNET 留言(0) 人氣()