package Test;
import java.util.Scanner;import java.io.*;public class TestStat {
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in);
String s = scanner.next();
System.out.println(s);
try{
File f = new File(s);
FileInputStream f1 = new FileInputStream(f);
DataInputStream in = new DataInputStream(f1);
int a;
int s1=0,n=1,w=0;
while((a=in.read())!=-1){
if(a==32){
s1++;
}else
if(a==13){
n++;
}else{
w++;
}
}
System.out.println(s1);
System.out.println(n);
System.out.println(w);
f1.close();
in.close();
}catch(IOException e){
System.out.println("文件读取失败!");
}
}}上面代码是我写的一个统计文件中空格s1,行n 字符w的数量`
问题是`
我每在代码中加一空行`  n自加1`  但是w也自加1`  这是为什么呢`
原题本来是要统计单词的数量的`
但我觉得太麻烦了`就改成了统计字符`
统计单词有没有什么好的办法呢`  除了判断两个空格间是否有字符外`