⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exercise16_1.java

📁 一个基于JAVA的简单的GUI编程
💻 JAVA
字号:
import java.io.*;
public class Exercise16_1 {
  public static void main(String args[]) {
    FileReader in = null;
    FileWriter out = null;
    int charCount = 0, wordCount = 0, lineCount = 0;
    boolean newWord = true, newLine = false;
    if (args.length != 1) {
      System.out.println("Usage: java Exercise16_1 file");
      System.exit(0);
    }
    try {
      in = new FileReader(new File(args[0]));
      int r;
      while ((r = in.read())!= -1) {
        charCount++;
        if ((char)r == '\n') {
          lineCount++;
          newLine = true;
        }
        else
          newLine = false;

        if (((r == ' ') || (r == '\n') || (r == '\t')) && !newWord)
          newWord = true;
        if ((r != ' ') && (r != '\n') && (r!= '\t') && newWord) {
          newWord = false;
          wordCount++;
        }
      }
      if (!newLine) lineCount++;
      System.out.println("File " + args[0] + " has \n" + charCount +
        " characters, \n" + wordCount + " words, and \n" + lineCount
        + " lines.");
    }
    catch (FileNotFoundException ex) {
      System.out.println("File not found: " + args[0]);
    }
    catch (IOException ex) {
      System.out.println(ex.getMessage());
    }
    finally {
      try {
        if (in != null) in.close();
        if (out != null) out.close();
      }
      catch (IOException ex) {}
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -