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

📄 randomdemo.java

📁 180个针对Java初学者的简单实例,包含了180個適合與初學者的源碼實例
💻 JAVA
字号:
// RandomAccessFile类及其常用方法的应用
import java.io.*;
 public class RandomDemo
	{
	public static void main(String[] args)
		{
		try
		{
		RandomAccessFile opRAD = new RandomAccessFile("test11_3.txt","rw");
			for(int i = 0; i<10; i++)
				opRAD.writeDouble(i*0.125);
			opRAD.close();

			opRAD = new RandomAccessFile("test11_3.txt","rw");
			opRAD.seek(4*8);
			opRAD.writeDouble(37.858);
			opRAD.close();

			opRAD = new RandomAccessFile("test11_3.txt","r");
			for(int i = 0; i<10; i++)
				System.out.println(i+ ":" + opRAD.readDouble());
			opRAD.close();
		}
		catch(FileNotFoundException e)
		{
			System.out.println(e);
			System.exit(-1);
		}
		catch(IOException e)
		{
			System.out.println(e);
			System.exit(-2);			
		}	
	}
}

⌨️ 快捷键说明

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