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

📄 complete11_2.java

📁 程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件
💻 JAVA
字号:
package questions.c11;
import java.io.*;
public class Complete11_2 {
   private String fileName;
   private int numberOfChars;
   public Complete11_2( String fn ) {
      fileName = fn;
   }
   public void countChars() {
      try {
         InputStream istream
            = new FileInputStream( fileName );
         int c;
         int charCount = 0;
         try {
            while ( ( c = istream.read() ) != -1 ) {
               charCount++;
            }
            numberOfChars = charCount;
         } finally {
            istream.close();
         }
      }
      catch( IOException iox ) {
         System.err.println( iox );
      }
   }
   public int getCharCount() {
      return numberOfChars;
   }
   public static void main( String[] args ) {
      if ( args.length >= 1 ) {
         Complete11_2 x
            = new Complete11_2( args[0] );
         x.countChars();
         System.out.println( x.getCharCount() );
      } else {
         System.out.println( "Please give a "
                             + "filename." );
      }
   }
}

⌨️ 快捷键说明

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