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

📄 randomaccessfiletest.java

📁 gcc的组建
💻 JAVA
字号:
import java.io.*;public class RandomAccessFileTest {  public static void main (String args[]) {    try {      File f = new File("/etc/passwd");      RandomAccessFile rf = new RandomAccessFile(f,"r");      long length = rf.length();      rf.seek(length - 10);      long pos = rf.getFilePointer();      if ( (length - 10) != pos )	throw new Exception("Bad value from getFilePointer(), " +			    pos + " !=" + (length - 10));      int i = rf.read();      byte b = rf.readByte();      boolean test = rf.readBoolean();      byte buf[] = new byte[40];      rf.seek(0);      rf.read(buf);      rf.close();      try {	length = rf.length();	throw new Exception("Got length from closed RandomAccessFile().");      } catch (IOException e) {}      String filename2 = "/var/tmp/testfile-remove";      File f2 = new File(filename2);      RandomAccessFile rf2 = new RandomAccessFile(filename2, "rw");      rf2.write(100);      rf2.write(buf);      rf2.close();      f2.delete();      System.out.println("PASSED: RandomAccessFile worked.");      System.exit(0);    } catch (Exception e) {      System.out.println("FAILED: "+e);    }  }}

⌨️ 快捷键说明

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