-
Socket通信模型查看全部
-
/* * 使用URL讀取網頁內容 */ public class Test03 { public static void main(String[] args) { try { //創建一個URL實例 URL url = new URL("http://www.baidu.com"); //通過URL的openStream方法獲取URL對象所表示的資源的字節輸入流 InputStream is = url.openStream(); //將字節輸入流轉換為字符輸入流 InputStreamReader isr = new InputStreamReader(is, "utf-8"); //為字符輸入流添加緩沖 BufferedReader br = new BufferedReader(isr); String data = br.readLine();//讀取數據 while (data != null) {//循環讀取數據 System.out.println(data);//輸出數據 data = br.readLine(); } br.close(); isr.close(); is.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }查看全部
-
使用URL讀取網頁內容查看全部
-
/* * URL常用方法 */ public class Test02 { public static void main(String[] args) { try { //創建一個URL實例 URL imooc=new URL("http://www.xianlaiwan.cn"); //?后面表示參數,#后面表示錨點 URL url=new URL(imooc, "/index.html?username=tom#test"); System.out.println("協議:"+url.getProtocol()); System.out.println("主機:"+url.getHost()); //如果未指定端口號,則使用默認的端口號,此時getPort()方法返回值為-1 System.out.println("端口:"+url.getPort()); System.out.println("文件路徑:"+url.getPath()); System.out.println("文件名:"+url.getFile()); System.out.println("相對路徑:"+url.getRef()); System.out.println("查詢字符串:"+url.getQuery()); } catch (MalformedURLException e) { e.printStackTrace(); } } }查看全部
-
URL簡介查看全部
-
網站URL形式舉例查看全部
-
URL簡介查看全部
-
/* * InetAddress類 */ public class test01 { public static void main(String[] args) throws UnknownHostException { // 獲取本機的InetAddress實例 InetAddress address = InetAddress.getLocalHost(); System.out.println("計算名:" + address.getHostName()); System.out.println("IP地址:" + address.getHostAddress()); byte[] bytes = address.getAddress();// 獲取字節數組形式的IP地址 System.out.println("字節數組形式的IP:" + Arrays.toString(bytes)); System.out.println(address);// 直接輸出InetAddress對象 // 根據機器名獲取InetAddress實例 // InetAddress address2=InetAddress.getByName("laurenyang"); InetAddress address2 = InetAddress.getByName("1.1.1.10"); System.out.println("計算名:" + address2.getHostName()); System.out.println("IP地址:" + address2.getHostAddress()); }查看全部
-
InetAddress:查看全部
-
java對網絡的支持查看全部
-
端口介紹:查看全部
-
端口介紹:查看全部
-
端口:標示不同的應用程序,反正衝突查看全部
-
IP地址格式查看全部
-
IP地址查看全部
舉報
0/150
提交
取消