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

📄 181-184.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=181-184//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="178-180.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="184-188.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading22"></A><FONT COLOR="#000077">Ls.getWildNames</FONT></H4>
<P>The <I>Ls.getWildNames</I> static method opens a standard file open dialog box. After a user selection, all the names are returned in a <I>String</I> array with the absolute path name.</P>
<!-- CODE //-->
<PRE>
   static public  String[] getWildNames(String wild) {
             File dir = Futil.getDirFile();
             String absPath = dir.getAbsolutePath();
             String[] fileNames = dir.list(new WildFilter(wild));
             System.out.println("getWildNames:"+absPath);
             for (int i=0; i &lt; fileNames.length; i++) {
             fileNames[i] = absPath+fileNames[i] ;
     }
     return fileNames;
   }
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading23"></A><FONT COLOR="#000077">Ls.wildToConsole</FONT></H4>
<P><I>Ls.wildToConsole</I> lists all the files to the standard output device. This is equivalent to the UNIX <I>ls *.wild</I> or the DOS <I>dir *.wild</I>.</P>
<!-- CODE SNIP //-->
<PRE>
   static public void wildToConsole(String wild) {
     String[] files = getWildNames(wild);
     System.out.println(files.length + " file(s):");
     for (int i=0; i &lt; files.length; i++)
          System.out.println("\t" + files[i]);
   }
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading24"></A><FONT COLOR="#000077">Ls.deleteWildFile</FONT></H4>
<P>Now for the dangerous stuff: a method that deletes all the files in a directory without confirmation.
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>WARNING:&nbsp;&nbsp;</B>Use this method with caution.<HR></FONT>
</BLOCKQUOTE>
<!-- CODE SNIP //-->
<PRE>
static public void deleteWildFiles(String wild) {
     String[] files = getWildNames(wild);
     System.out.println(files.length + " file(s):");
     for (int i=0; i &lt; files.length; i++)
     deleteFile(files[i]);
}
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading25"></A><FONT COLOR="#000077">Ls.WordPrintMerge</FONT></H4>
<P><I>Ls.WordPrintMerge</I> gets all the files that end with a <B>PICT</B> suffix and creates Microsoft Word print merge commands that will include the pict files in a single Word document. We used this utility in creating the figure manuscript for Chapter 1 of this book.</P>
<!-- CODE //-->
<PRE>
static public void WordPrintMerge() {
     String wild = "PICT";
     String[] files = getWildNames(wild);
     System.out.println(files.length + " file(s):");
     int fileNumber;
     for (int i=0; i &lt; files.length; i++) {
          fileNumber = i + 1;
          System.out.print("Figure *."+
                     fileNumber +
                     ".       INCLUDE "hd:current:Java book:chapter
I:batch 1 rev1:picts:\");"
                     System.out.println(files[i]+"&gt;&gt;");
           }
 }
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading26"></A><FONT COLOR="#000077">Ls.lowerFileNames</FONT></H4>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>WARNING:&nbsp;&nbsp;</B><I>Ls.lowerFileNames</I> takes a <I>File</I> instance and recursively traverses the file system, converting all file names to lowercase!<HR></FONT>
</BLOCKQUOTE>
<P>Now for the really dangerous (and fun!) stuff. There is no single command in most operating systems for doing this (for obvious reasons). <I>Ls.lowerFileNames</I> is used to maintain Web sites whose file names do not match the case of the file names in the hypertext references. This chore is particularly painful for Web masters who port Web sites from one file system to another. For example, on a DOS system the file names may appear as uppercase. On a Mac or UNIX file system, files are mixed-case.</P>
<!-- CODE //-->
<PRE>
public void lowerFileNames( File thePath ){
String[] fileNames = thePath.list();
String pathstr = thePath.getPath();
for( int i=0;fileNames != null &#38;&#38; i&lt; fileNames.length; i++ ) {
  String aFileName = fileNames[ i ];
  String newFileName = aFileName.toLowerCase();
  File theFile = new File( pathstr, aFileName );
  if( theFile.isFile() ){
  //rename theFile to lowercase
  System.out.print( i+":" + aFileName );
  theFile.renameTo( new File( pathstr, newFileName ) );
  System.out.println( "\t==&gt;\t"+newFileName );
  }else{
  //case theFile is Dir, in the Dir,
  // repeat same procedure
  System.out.println( "Dir:"+aFileName );
  lowerFileNames( new File( pathstr+aFileName ));
  }
  }
return;
}//lowerFileNames
</PRE>
<!-- END CODE //-->
<H3><A NAME="Heading27"></A><FONT COLOR="#000077">The FileOutputStream Class</FONT></H3>
<P>The <I>FileOutputStream</I> class resides in the <I>java.io</I> package. Instances of <I>FileOutputStream</I> are used as targets of the <I>close</I> method. When an instance of a <I>FileOutputStream</I> is made, the file is opened for write access.</P>
<P>Because the creation and closing of a <I>FileOutputStream</I> instance can throw an <I>IOException</I>, operations involving the use of a <I>FileOutputStream</I> are surrounded by <I>try</I> and <I>catch</I>.</P>
<H4 ALIGN="LEFT"><A NAME="Heading28"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
public class FileOutputStream extends OutputStream {
  public FileOutputStream(String name) throws IOException
  public FileOutputStream(File file) throws IOException
  public FileOutputStream(FileDescriptor fdObj)
  public native void write(int b) throws IOException;
  public void write(byte b[]) throws IOException
  public void write(byte b[], int off, int len) throws IOException
  public native void close() throws IOException;
  public final FileDescriptor getFD()  throws IOException
}
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading29"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>To open a file for write using a standard file open save box, define a <I>FileOutputStream</I> instance by using the <I>Futil.getWriteFileName()</I>:</P>
<!-- CODE SNIP //-->
<PRE>
FileOutputStream output_stream = new
FileOutputStream(getWriteFileName());
</PRE>
<!-- END CODE SNIP //-->
<P>Suppose the following variables are predefined:
</P>
<!-- CODE SNIP //-->
<PRE>
String fileName;
File file;
FileDescriptor fd;
byte b, bytes[];
int offset, length;
</PRE>
<!-- END CODE SNIP //-->
<P>To open a file for write access (remember to use <I>try</I> and <I>catch</I>), use this code:</P>
<!-- CODE SNIP //-->
<PRE>
fos = new FileOutputStream(name);
</PRE>
<!-- END CODE SNIP //-->
<P>To open a file using a <I>File</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
fos = new FileOutputStream(file);
</PRE>
<!-- END CODE SNIP //-->
<P>To open a file using a <I>FileDescriptor</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
fos = new FileOutputStream(fd);
</PRE>
<!-- END CODE SNIP //-->
<P>To write a byte of data:
</P>
<!-- CODE SNIP //-->
<PRE>
fos.write(b);
</PRE>
<!-- END CODE SNIP //-->
<P>To write an array of bytes:
</P>
<!-- CODE SNIP //-->
<PRE>
fos.write(bytes);
</PRE>
<!-- END CODE SNIP //-->
<P>To write a subarray of bytes:
</P>
<!-- CODE SNIP //-->
<PRE>
fos.write(bytes, offset, length);
</PRE>
<!-- END CODE SNIP //-->
<P>To close the <I>FileOutputStream</I>:</P>
<!-- CODE SNIP //-->
<PRE>
fos.close();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the file descriptor:
</P>
<!-- CODE SNIP //-->
<PRE>
fd = fos.getFD();
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="178-180.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="184-188.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 + -