Re: new一個URL物件

看板java作者 (逋逋狗)時間19年前 (2006/03/23 16:13), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/4 (看更多)
※ 引述《oishii (喔帥)》之銘言: : //這個是我的程式碼 : URL u = new URL("http://udn.com/"); : 編譯出現了以下的錯誤 : AppletSke1.java:8: unreported exception : java.net.MalformedURLException; must be : caught or declared to be thrown : URL u = new URL("http://udn.com/"); : ^ : 這是哪裡出了問題呢?請求各位大大協助,希望不是太蠢的錯誤... 謝謝 不知道你其他的程式碼如何寫的...可能錯在其他行,我這樣寫就沒問題呀 import java.lang.*; import java.net.*; import java.io.*; public class URLtest { public static void main(String[] para) { String lineStr="",contStr=""; try { URL myurl = new URL("http://udn.com"); BufferedReader myurlReader = new BufferedReader(new InputStreamReader(myurl.openStream())); while((lineStr = myurlReader.readLine()) != null) { contStr = contStr+lineStr+"\n"; } System.out.println(contStr); } catch(Exception err) { System.out.println("ERROR"); } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.125.32.41
文章代碼(AID): #148bYgny (java)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 4 篇):
1
2
文章代碼(AID): #148bYgny (java)