java中講講InputStreamReader的用法,舉例?
阿新 • • 發佈:2018-09-25
stat url ron target system cep may efault rom
例:2.4.1
import java.io.*;
public class TestMark_to_win {
public static void main(String args[]) throws Exception {
// ////////////////from console to string,\u00A0
System.out.println("from console to string ");
/*An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform‘s default charset may be accepted. InputStreamReader(InputStream in) Create an
InputStreamReader that uses the default charset.
*/
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
2.4 InputStreamReader的用法 (視頻下載) (全部書籍)
馬
克-to-win:InputStreamReader
從文字上分析:InputStream是字節流的意思,Reader是字符流的意思。InputStreamReader這個類就是用來把字節流轉換成字符流的。System.in代表控制臺輸入。它天生是個字節流。參見我前面寫的InputStream小節的例:2.1.1,
我們發現如果向控制臺輸入中文,控制臺是處理不了的,但這時如果我們用InputStreamReader這個工具轉換一下,問題就解決了。下一章我們要
講的網絡傳輸,天生也是以字節形式進行的,所以字節流和字符流之間也必然轉換一下。
例:2.4.1
import java.io.*;
public class TestMark_to_win {
public static void main(String args[]) throws Exception {
// ////////////////from console to string,\u00A0
System.out.println("from console to string ");
/*An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform‘s default charset may be accepted. InputStreamReader(InputStream in) Create an
InputStreamReader that uses the default charset.
*/
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
詳情黏貼以下網址在地址欄後請進:http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner8_web.html#UsageOfInputStreamReader
java中講講InputStreamReader的用法,舉例?