标签:close next mil exception out cep 字符 scan class
public class Test {
public static void main(String[] args) throws Exception{
Scanner input=new Scanner(System.in);
System.out.println("请输入路径");
String path=input.next();
int charNum= 0 ;
int wordsNum= 0;
int lineNum = 0;
InputStreamReader isr = new InputStreamReader(new FileInputStream(path));
BufferedReader br = new BufferedReader(isr);
while( br.read()!= -1){
String s = br.readLine();
charNum+=s.length();
wordsNum +=s.split(" ").length;
lineNum ++;
}
isr.close();//关闭
System.out.println("字符数:"+charNum+"\t单词数:"+wordsNum+"行 数:"+lineNum);
}
}
标签:close next mil exception out cep 字符 scan class
原文地址:http://www.cnblogs.com/Sherryhan/p/5991098.html