统计一个文件中的字符数,单词数,制表符。
来源:互联网 发布:js密码和确认密码校验 编辑:程序博客网 时间:2024/05/17 06:33
import java.io.*;import java.util.*;public class TongJi { public static void main(String args[]) throws Exception { int charCount = 0, wordCount = 0, lineCount = 0; // Check usage if (args.length != 1) { System.out.println("Usage: java TongJi file"); System.exit(0); } // Check if source file exists File sourceFile = new File(args[0]); if (!sourceFile.exists()) { System.out.println("Source file " + args[0] + " not exist"); System.exit(0); } // Create a Scanner for the file Scanner input = new Scanner(sourceFile); while (input.hasNext()) { String s = input.nextLine(); charCount += s.length(); lineCount++; wordCount += countWords(s); } System.out.println("File " + sourceFile + " has "); System.out.println(charCount + " characters"); System.out.println(wordCount + " words"); System.out.println(lineCount + " lines"); } private static int countWords(String s) { Scanner input = new Scanner(s); int count = 0; while (input.hasNext()) { input.next(); count++; } return count; }}
1 0
- 统计一个文件中的字符数,单词数,制表符。
- java统计一个文件的字符数,单词数,行数
- 统计一个句子中的单词数
- 统计输入中的行数,单词数,字符数
- 统计文件内的字符数,单词数,行数
- 统计一句话中的单词数
- 统计文件的单词数
- Scala 统计文件单词数
- python快速统计一个文件包含的单词数
- java利用HashMap统计文件中的单词数
- 编译器DIY之———统计英文文本中的单词数,字符数和行数
- 2017.8.19 利用python统计文档中的单词数,行数和字符数
- C++ 读取文件并统计字符数、行数和单词数
- C语言统计输入行数、单词数、字符数
- 统计行数、单词数与字符数(C语言)
- C语言统计输入行数、单词数、字符数
- 统计一段文字的单词数、字符数和行数
- 2.统计输入的行数,单词数和字符数
- API中的对象Runtime
- C++primer plus第六版课后编程练习答案2.7
- 使用android SpannableStringBuilder实现图文混排源码
- Tag system implementation
- Summary of problems when coding
- 统计一个文件中的字符数,单词数,制表符。
- 自动换行LinearLayout
- Dropdownlist验证是否选择
- android 修改文本选中默认样式
- 进程与线程的一个简单解释
- 建立一个程序,写2个线程,同时对一个文件里面写入字符串,另外一个程序读取输出在控制台,保证读取的实时性。
- Cocos2d-x 常用语句
- 安卓带点击效果的圆角button
- 世界坐标转UGUI屏幕坐标