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

📄 readcharacters.java

📁 Java Classic Examples是我买的两本书:《JAVA经典实例》和《java入门经典源代码》里边附送光盘里带的源码
💻 JAVA
字号:
// Using the push back reader
import java.io.*;

class ReadCharacters
{
  public static void main(String[] args)
  {
    try
    {
      String dirName = "c:\\JunkData\\";         // Directory for the output file
      String fileName = "Proverbs.txt";          // Name of the output file 

      File input = new File(dirName, fileName);  // The file object

      PushbackReader in = new PushbackReader(
                                           new BufferedReader(
                                           new FileReader(input)));

      int c;                                     // Character store
      while(true)
      {
        String number ="";                       // String length as characters

        // Get the characters for the length
        while(Character.isDigit((char)(c = in.read())))
          number += (char)c;

        if(c==-1)                                // Check for end of file
          break;                                 // End the loop
        else                                     // It is not end of file so
          in.unread(c);                          // push back the last character

        char[] proverb = new char[Integer.parseInt(number)];
        in.read(proverb);                        // Read a proverb
        System.out.println(proverb);
      }
    }
    catch(FileNotFoundException e)               // Stream creation exception
    {
      System.err.println(e);
      return;
    }
    catch(IOException e)                         // File read exception
    {
      System.err.println("Error reading input file" + e );
      return;
    }
  }
}

⌨️ 快捷键说明

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