久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

node.js - java的輸入流、輸出流怎么理解?

瀏覽:136日期:2023-11-01 09:51:18

問題描述

import java.net.*;import java.io.*;public class URLConnDemo{ public static void main(String [] args) { try { URL url = new URL('http://www.xxx.com'); URLConnection urlConnection = url.openConnection(); HttpURLConnection connection = null; if(urlConnection instanceof HttpURLConnection) { connection = (HttpURLConnection) urlConnection; } else { System.out.println('請輸入 URL 地址'); return; } BufferedReader in = new BufferedReader( new InputStreamReader(connection.getInputStream())); String urlString = ''; String current; while((current = in.readLine()) != null) { urlString += current; } System.out.println(urlString); }catch(IOException e) { e.printStackTrace(); } }}

從這段代碼來看,請求一個url并把內容讀取出來顯示,但是為什么這里用到getInputStream,應該不是getOutStream 輸出嗎?

問題解答

回答1:

InputStream 是用來讀取的,OutputStream 是用來寫入的;換句話說,輸入流是指輸入到系統中的流,系統從這個流中讀取內容;輸出流是指從系統輸出的流,系統往這個流中寫入內容。這個取名方式是站在使用者的角度,而不是 Stream 對象的角度。用過幾次就習慣了。

標簽: java
相關文章:
主站蜘蛛池模板: 天峨县| 翼城县| 城口县| 郸城县| 卢龙县| 奈曼旗| 阿城市| 鄂伦春自治旗| 哈巴河县| 兰溪市| 大港区| 清水县| 夏津县| 高碑店市| 陵川县| 沈丘县| 和林格尔县| 尚志市| 石阡县| 太谷县| 垦利县| 新源县| 龙游县| 南召县| 仪陇县| 离岛区| 凌源市| 宜黄县| 荔波县| 南雄市| 贵州省| 渭南市| 昌都县| 遂宁市| 西乡县| 江陵县| 阜宁县| 丰镇市| 衡阳市| 刚察县| 黄冈市|