我是对java了解并不多,有没有最浅显的方法写这个程序,该怎么写
import java.io.*;
public class A {
public static void main(String args[]) throws IOException {
File f1 = new File("test.txt");//这里是文本文件的路径
BufferedReader fis = new BufferedReader(new FileReader(f1));
int charCount = 0;
int wordsCount = 0;
int lineCount = 0;
String aLine = fis.readLine();
while (aLine != null) {
charCount = charCount + aLine.length();
String[] words = aLine.split("[,.]");
wordsCount = wordsCount + words.length;
lineCount = lineCount + 1;
aLine = fis.readLine();
}
System.out.println("charCount = " + charCount);
System.out.println("wordsCount = " + wordsCount);
System.out.println("lineCount = " + lineCount);
}
}
实话跟你说,楼上说的答案可能解决不了你的问题,
你说对不对?