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

📄 readrandomaccessfile.java

📁 精通Java核心技术源代码
💻 JAVA
字号:
import java.io.*;

   public class ReadRandomAccessFile 
  {
 	    public static void main(String[] args) 
       {
	        try {
	            long dataPosition = 0;
	            int data = 0;
               RandomAccessFile raf = new RandomAccessFile("datafile", "r");
               dataPosition = raf.readLong();// 获得欲读数据的位置
               raf.seek(dataPosition);      
               data = raf.readInt();        // 读数据
               raf.close();
               System.out.println("The data is: " + data);
           }
  	        catch (FileNotFoundException e) {
	            System.err.println("This shouldn't happen: " + e);
           } 
           catch (IOException e) {
	            System.err.println("Writing error: " + e);
	        }
       }
   }

⌨️ 快捷键说明

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