我是对java了解并不多,有没有最浅显的方法写这个程序,该怎么写
2条回答 默认 最新
南七灵 2021-11-29 09:09关注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); } }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 3