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

📄 184-188.html

📁 dshfghfhhgsfgfghfhfghgfhfghfgh fg hfg hh ghghf hgf hghg gh fg hg hfg hfh f hg hgfh gkjh kjkh g yj f
💻 HTML
字号:
<HTML>
<HEAD>
<META name=vsisbn content="1558515682"><META name=vstitle content="Java Digital Signal Processing"><META name=vsauthor content="Douglas A. Lyon"><META name=vsimprint content="M&T Books"><META name=vspublisher content="IDG Books Worldwide, Inc."><META name=vspubdate content="11/01/97"><META name=vscategory content="Web and Software Development: Programming, Scripting, and Markup Languages: Java"><TITLE>Java Digital Signal Processing:Futil Recipes for Feudal Times</TITLE>
<!-- HEADER --><STYLE type="text/css">  <!-- A:hover  { 	color : Red; } --></STYLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<!--ISBN=1558515682//-->
<!--TITLE=Java Digital Signal Processing//-->
<!--AUTHOR=Douglas A. Lyon//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=4//-->
<!--PAGES=184-188//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="181-184.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="188-192.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading30"></A><FONT COLOR="#000077">Futil.getFileOutputStream</FONT></H4>
<P>A simple way to get a file output stream&#151;by prompting the user with a file dialog box and intercepting the possible resulting exceptions&#151;is given next. The <I>Futil.getFileOutputStream</I> method returns null if the output file cannot be made.</P>
<!-- CODE //-->
<PRE>
public static FileOutputStream getFileOutputStream() {
    FileOutputStream fos = null;
    try {fos =
              new FileOutputStream(getWriteFileName());
         }
    catch (IOException e) {
              System.out.println("futil:Could not create file");
         }
         return fos;
    }
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading31"></A><FONT COLOR="#000077">Futil.closeOutputStream</FONT></H4>
<P>As with the <I>getFileOutputStream</I>, there is a <I>closeOutputStream</I> method.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>Any subclass of the <I>OutputStream</I> (such as <I>FileOutputStream</I>) will automatically be cast into an <I>OutputStream</I> instance during the call. Thus, there is no need for a <I>Futil.closeFileOutputStream</I> method.<HR></FONT>
</BLOCKQUOTE>
<!-- CODE SNIP //-->
<PRE>
 public static void closeOutputStream(OutputStream os) {
   try {os.close();} // end try
    catch (IOException exe)
    {System.out.println(
     "futil: could not close outputstream");}
   }
</PRE>
<!-- END CODE SNIP //-->
<H3><A NAME="Heading32"></A><FONT COLOR="#000077">The PrintStream Class</FONT></H3>
<P>The <I>PrintStream</I> class resides in the <I>java.io</I> package. An instance of <I>PrintStream</I> exists in <I>System.out</I> and has been introduced informally using</P>
<!-- CODE SNIP //-->
<PRE>
System.out.println("Hello World");
</PRE>
<!-- END CODE SNIP //-->
<P>A <I>PrintStream</I> instance can be explicitly flushed. When flushed, the buffered output will be written. A newline can be used to trigger a flush.</P>
<H4 ALIGN="LEFT"><A NAME="Heading33"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
public class PrintStream extends FilterOutputStream {
  public PrintStream(OutputStream out)
  public PrintStream(OutputStream out, boolean autoflush)
  public void write(int b)
  public void write(byte b[], int off, int len)
  public void flush()
  public void close()
  public boolean checkError()
  public void print(Object obj)
  synchronized public void print(String s)
  synchronized public void print(char s[])
  public void print(char c)
  public void print(int i)
  public void print(long l)
  public void print(float f)
  public void print(double d)
  public void print(boolean b)
  public void println()
  synchronized public void println(Object obj)
  synchronized public void println(String s)
  synchronized public void println(char s[])
  synchronized public void println(char c)
  synchronized public void println(int i)
  synchronized public void println(long l)
  synchronized public void println(float f)
  synchronized public void println(double d)
  synchronized public void println(boolean b)
}
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading34"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>Suppose the following variables are predefined:
</P>
<!-- CODE //-->
<PRE>
OutputStream os;
PrintStream ps=new PrintStream(os);
boolean autoflush;
byte b, bytes[];
int offset, length;
boolean aboolean;
Object object;
String string;
char aChar, charArray[];
int i;
long l;
float f;
double d;
</PRE>
<!-- END CODE //-->
<P>To make a <I>PrintStream</I> instance from any <I>OutputStream</I> instance, use:</P>
<!-- CODE SNIP //-->
<PRE>
ps = new PrintStream(os);
</PRE>
<!-- END CODE SNIP //-->
<P>To automatically flush the output stream after every new line, set autoflush = true:
</P>
<!-- CODE SNIP //-->
<PRE>
ps = new PrintStream(os, autoflush);
</PRE>
<!-- END CODE SNIP //-->
<P>To write a byte:
</P>
<!-- CODE SNIP //-->
<PRE>
ps.write(b);
</PRE>
<!-- END CODE SNIP //-->
<P>To write a subarray:
</P>
<!-- CODE SNIP //-->
<PRE>
ps.write(bytes, offset, length);
</PRE>
<!-- END CODE SNIP //-->
<P>To flush the stream:
</P>
<!-- CODE SNIP //-->
<PRE>
ps.flush();
</PRE>
<!-- END CODE SNIP //-->
<P>To close the stream:
</P>
<!-- CODE SNIP //-->
<PRE>
ps.close();
</PRE>
<!-- END CODE SNIP //-->
<P>To flush the print stream with output stream error messages and return true if an error occurred during the life of the <I>PrintStream</I>:</P>
<!-- CODE SNIP //-->
<PRE>
aboolean = ps.checkError();
</PRE>
<!-- END CODE SNIP //-->
<P>To print a newline:
</P>
<!-- CODE SNIP //-->
<PRE>
ps.println();
</PRE>
<!-- END CODE SNIP //-->
<P>To print an object or an object&#43;newline:
</P>
<!-- CODE SNIP //-->
<PRE>
ps.print(object);
ps.println(object);
</PRE>
<!-- END CODE SNIP //-->
<P>To print a <I>String</I> or a string&#43;newline:</P>
<!-- CODE SNIP //-->
<PRE>
ps.print(string);
ps.println(string);
</PRE>
<!-- END CODE SNIP //-->
<P>To print a <I>char</I> or an array of <I>char</I>:</P>
<!-- CODE SNIP //-->
<PRE>
ps.print(aChar);
ps.print(charArray);
</PRE>
<!-- END CODE SNIP //-->
<P>To print an <I>int</I>, <I>long</I>, <I>float</I>, or <I>double</I>:</P>
<!-- CODE SNIP //-->
<PRE>
ps.print(i);
ps.print(l);
ps.print(f);
ps.print(d);
</PRE>
<!-- END CODE SNIP //-->
<P>To print an <I>int</I>, <I>long</I>, <I>float</I>, or <I>double</I> &#43; newline:</P>
<!-- CODE SNIP //-->
<PRE>
ps.println(i);
ps.println(l);
ps.println(f);
ps.println(d);
</PRE>
<!-- END CODE SNIP //-->
<P>To print a <I>boolean</I> or <I>boolean</I> &#43; newline:</P>
<!-- CODE SNIP //-->
<PRE>
ps.print(aboolean);
ps.println(aboolean);
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="181-184.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="188-192.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>

<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright &copy; <a href="/reference/idgbooks00001.html">IDG Books Worldwide, Inc.</a></font></div>
<!-- all of the reference materials (books) have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --></BODY></HTML><!-- END FOOTER -->

⌨️ 快捷键说明

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