⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tij0114.html

📁 学习java的经典书籍
💻 HTML
📖 第 1 页 / 共 3 页
字号:
or 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>Writer</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">).</FONT><P></DIV>
<DIV ALIGN=LEFT><TABLE BORDER>
<COLGROUP>
      <COL width="139">
      <COL width="198">
</COLGROUP>
<TR VALIGN="TOP">
<TH WIDTH=139 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Filters:</FONT><P><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Java
1.0<A NAME="Index1225"></A>
class
</FONT><P></DIV>
</TH>
<TH WIDTH=198 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Corresponding
Java 1.1<A NAME="Index1226"></A>
class
</FONT><P></DIV>
</TH>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=139 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>FilterInputStream</B></FONT><P></DIV>
</TD>
<A NAME="Index1227"></A><A NAME="Index1228"></A><TD WIDTH=198 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>FilterReader</B></FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=139 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>FilterOutputStream</B></FONT><P></DIV>
</TD>
<A NAME="Index1229"></A><A NAME="Index1230"></A><TD WIDTH=198 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>FilterWriter</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
(
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>abstract</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
class with no subclasses)
</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=139 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>BufferedInputStream</B></FONT><P></DIV>
</TD>
<A NAME="Index1231"></A><A NAME="Index1232"></A><TD WIDTH=198 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>BufferedReader</B></FONT><P><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">(also
has <A NAME="Index1233"></A><A NAME="Index1234"></A></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>readLine(&#160;)</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">)</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=139 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>BufferedOutputStream</B></FONT><P></DIV>
</TD>
<A NAME="Index1235"></A><A NAME="Index1236"></A><TD WIDTH=198 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>BufferedWriter</B></FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=139 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>DataInputStream</B></FONT><P></DIV>
</TD>
<TD WIDTH=198 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">use
<A NAME="Index1237"></A><A NAME="Index1238"></A></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>DataInputStream</B></FONT><P><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">(Except
when you need to use 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>readLine(&#160;)</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">,
when you should use a 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>BufferedReader</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">)</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=139 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>PrintStream</B></FONT><P></DIV>
</TD>
<A NAME="Index1239"></A><A NAME="Index1240"></A><TD WIDTH=198 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>PrintWriter</B></FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=139 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>LineNumberInputStream</B></FONT><P></DIV>
</TD>
<A NAME="Index1241"></A><A NAME="Index1242"></A><TD WIDTH=198 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>LineNumberReader</B></FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=139 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>StreamTokenizer</B></FONT><P></DIV>
</TD>
<A NAME="Index1243"></A><A NAME="Index1244"></A><TD WIDTH=198 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>StreamTokenizer</B></FONT><P><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">(use
constructor that takes a 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>Reader</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
instead)
</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=139 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>PushBackInputStream</B></FONT><P></DIV>
</TD>
<A NAME="Index1245"></A><A NAME="Index1246"></A><TD WIDTH=198 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>PushBackReader</B></FONT><P></DIV>
</TD>
</TR>
</TABLE></DIV>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">There&#8217;s
one direction that&#8217;s quite clear: Whenever you want to use 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>readLine(&#160;)</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">,
you shouldn&#8217;t do it with a 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>DataInputStream</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
any more (this is met with a deprecation message at compile time), but instead
use a 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>BufferedReader</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">.
Other than this, 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>DataInputStream</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
is still a &#8220;preferred&#8221; member of the Java 1.1 IO library.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">To
make the transition to using a 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>PrintWriter</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
easier, it has constructors that take any 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>OutputStream</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
object. However, 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>PrintWriter</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
has no more support for formatting than 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>PrintStream</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
does; the interfaces are virtually the same.
</FONT><a name="_Toc408018631"></a><P></DIV>
<A NAME="Heading336"></A><H3 ALIGN=LEFT>
Unchanged
Classes
</H3>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Apparently,
the Java library designers felt that they got some of the classes right the
first time so there were no changes to these and you can go on using them as
they are:
</FONT><P></DIV>
<DIV ALIGN=LEFT><TABLE BORDER>
<COLGROUP>
      <COL width="166">
</COLGROUP>
<TR VALIGN="TOP">
<TH WIDTH=166 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Java
1.0<A NAME="Index1247"></A>
classes without corresponding Java 1.1<A NAME="Index1248"></A>
classes
</FONT><P></DIV>
</TH>
</TR>
<A NAME="Index1249"></A><A NAME="Index1250"></A><TR VALIGN="TOP">
<TD WIDTH=166 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>DataOutputStream</B></FONT><P></DIV>
</TD>
</TR>
<A NAME="Index1251"></A><A NAME="Index1252"></A><TR VALIGN="TOP">
<TD WIDTH=166 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>File</B></FONT><P></DIV>
</TD>
</TR>
<A NAME="Index1253"></A><A NAME="Index1254"></A><TR VALIGN="TOP">
<TD WIDTH=166 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>RandomAccessFile</B></FONT><P></DIV>
</TD>
</TR>
<A NAME="Index1255"></A><A NAME="Index1256"></A><TR VALIGN="TOP">
<TD WIDTH=166 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>SequenceInputStream</B></FONT><P></DIV>
</TD>
</TR>
</TABLE></DIV>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">The
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>DataOutputStream</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">,
in particular, is used without change, so for storing and retrieving data in a
transportable format you&#8217;re forced to stay in the 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>InputStream</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
and 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>OutputStream</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
hierarchies.
</FONT><a name="_Toc408018632"></a><P></DIV>
<A NAME="Heading337"></A><H3 ALIGN=LEFT>
An
example
</H3>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">To
see the effect of the new classes, let&#8217;s look at the appropriate portion
of the 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>IOStreamDemo.java</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
example modified to use the 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>Reader</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
and 
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>Writer</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
classes:
</FONT><P></DIV>

<font color="#990000"><PRE><font color="#009900">//: NewIODemo.java</font>
<font color="#009900">// Java 1.1 IO typical usage</font>
<font color="#0000ff">import</font> java.io.*;

<font color="#0000ff">public</font> <font color="#0000ff">class</font> NewIODemo {
  <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">void</font> main(String[] args) {
    <font color="#0000ff">try</font> {
      <font color="#009900">// 1. Reading input by lines:</font>
      BufferedReader in =
        <font color="#0000ff">new</font> BufferedReader(
          <font color="#0000ff">new</font> FileReader(args[0]));
      String s, s2 = <font color="#0000ff">new</font> String();
      <font color="#0000ff">while</font>((s = in.readLine())!= <font color="#0000ff">null</font>)
        s2 += s + "\n";
      in.close();

      <font color="#009900">// 1b. Reading standard input:</font>
      BufferedReader stdin =
        <font color="#0000ff">new</font> BufferedReader(
          <font color="#0000ff">new</font> InputStreamReader(System.in));      
      System.out.print("Enter a line:");
      System.out.println(stdin.readLine());

      <font color="#009900">// 2. Input from memory</font>
      StringReader in2 = <font color="#0000ff">new</font> StringReader(s2);
      <font color="#0000ff">int</font> c;
      <font color="#0000ff">while</font>((c = in2.read()) != -1)
        System.out.print((<font color="#0000ff">char</font>)c);

      <font color="#009900">// 3. Formatted memory input</font>
      <font color="#0000ff">try</font> {
        DataInputStream in3 =
          <font color="#0000ff">new</font> DataInputStream(
            <font color="#009900">// Oops: must use deprecated class:</font>
            <font color="#0000ff">new</font> StringBufferInputStream(s2));
        <font color="#0000ff">while</font>(<font color="#0000ff">true</font>)
          System.out.print((<font color="#0000ff">char</font>)in3.readByte());
      } <font color="#0000ff">catch</font>(EOFException e) {
        System.out.println("End of stream");
      }

      <font color="#009900">// 4. Line numbering &amp; file output</font>
      <font color="#0000ff">try</font> {
        LineNumberReader li =
          <font color="#0000ff">new</font> LineNumberReader(
            <font color="#0000ff">new</font> StringReader(s2));
        BufferedReader in4 =
          <font color="#0000ff">new</font> BufferedReader(li);
        PrintWriter out1 =
          <font color="#0000ff">new</font> PrintWriter(
            <font color="#0000ff">new</font> BufferedWriter(
              <font color="#0000ff">new</font> FileWriter("IODemo.out")));
        <font color="#0000ff">while</font>((s = in4.readLine()) != <font color="#0000ff">null</font> )
          out1.println(
            "Line " + li.getLineNumber() + s);
        out1.close();
      } <font color="#0000ff">catch</font>(EOFException e) {
        System.out.println("End of stream");
      }

      <font color="#009900">// 5. Storing &amp; recovering data</font>
      <font color="#0000ff">try</font> {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -