complete11_2.java
来自「北京大学出版社的」· Java 代码 · 共 42 行
JAVA
42 行
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 + =
减小字号Ctrl + -
显示快捷键?