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

📄 displayreversed.java

📁 《A first book of java》by Gary J.Bronson 北大出版社
💻 JAVA
字号:
import java.io.*;
public class DisplayReversed
{
  static final int SIZEOFCHAR = 2;   // there are 2 bytes per char
 
  public static void main(String[] args)
    throws java.io.IOException
  {
    String fileName = "test.dat";
    char ch; 
    long last, position, setbytepos;

      // set up the basic random access input/output stream
    RandomAccessFile raf = 
        new RandomAccessFile(fileName, "rw");

    last = raf.length();  // get length of the file
    System.out.println("last = " + last);
    position = last - SIZEOFCHAR; // starting position of last char
    while(position >= 0)
    {
      raf.seek(position);   // move to the character
      ch = raf.readChar();  
      System.out.print(ch + " | ");
      position = position - SIZEOFCHAR;  // position of prior char
    }      

    raf.close();
  }
}

⌨️ 快捷键说明

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