📄 right4_7_3.htm
字号:
<html><head><title>JAVA编程语言</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link rel="stylesheet" href="../../../css/text.css" type="text/css"><script language="JavaScript"><!--function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features);}//--></script></head><body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" ><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td valign="top"> <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF"> <tr> <td valign="top"> <p class="pt9-black"> <span class="zhongdian">◇ 生成流对象<a name="01"></a></span><br> <br> public BufferedReader(Reader in); <font color="339900">//使用缺省的缓冲区大小</font><br> public BufferedReader(Reader in, int sz); <font color="339900">//sz为缓冲区的大小</font><br> public BufferedWriter(Writer out);<br> public BufferedWriter(Writer out, int sz);<br> <br> <span class="zhongdian">◇ 读入/写出字符<a name="02"></a></span><br> <br> 除了Reader和Writer中提供的基本的读写方法外,增加对整行字符的处理。<br> public String readLine() throws IOException; <font color="339900">//读一行字符</font><br> public void newLine() throws IOException; <font color="339900">//写一行字符<br> </font><b><br> <img src="../../../images/html/liti.gif" width="38" height="38" align="absbottom" title="例题">【例4-4】<a name="03"></a></b><br> <br> import java.io.*;<br> public class NumberInput{<br> public static void main(String args[]){<br> try{<br> InputStreamReader ir;<br> BufferedReader in;<br> ir=new InputStreamReader(System.in); <br> <font color="339900">//从键盘接收了一个字符串的输入,并创建了一个字符输入流的对象</font><br> in=new BufferedReader(ir);<br> String s=in.readLine();<br> <font color="339900">//从输入流in中读入一行,并将读取的值赋值给字符串变量s</font><br> System.out.println("Input value is: "+s);<font color="339900"><br> </font>int i = Integer.parseInt(s);<font color="339900">//转换成int型</font><br> i*=2;<br> System.out.println("Input value changed after doubled: "+i);<br> }catch(IOException e)<br> {System.out.println(e);}<br> }<br> }<br> <br> <a href="#03" onClick="MM_openBrWindow('tanchu1.htm','','width=200,height=150')"><font color="#FF0000">查看运行结果</font></a><br> <br> <font color="000099">注意:在读取字符流时,如果不是来自于本地的,比如说来自于网络上某处的与本地编码方式不同的机器,那么我们在构造输入流时就不能简单地使用本地缺省的编码方式,否则读出的字符就不正确;为了正确地读出异种机上的字符,我们应该使用下述方式构造输入流对象:<br> <br> ir = new InputStreamReader(is, "8859_1");<br> <br> 采用ISO 8859_1编码方式,这是一种映射到ASCII码的编码方式,可以在不同平台之间正确转换字符。<br> </font><br> </p> </td> </tr> </table> </td> </tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -