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

📄 randomdemo.java

📁 Java面向对象编程(随书配套源代码) 阐述了面向对象编程的思想
💻 JAVA
字号:
package chapter13;
import java.io.*;
public class RandomDemo
{
	public static void main(String args[]) throws IOException
	{
		int lineNo;
		long fp;
		InputStreamReader stdin=new InputStreamReader(System.in);
		BufferedReader bufin=new  BufferedReader(stdin);
		RandomAccessFile file=new RandomAccessFile("random.txt","rw");
		System.out.println("请输入6个字符串:\n");
		int len[]=new int[6];
		String strInput[]=new String[6];
		for(int i=0;i<6;i++)
		{
			System.out.print("行号"+(i+1)+":");
			strInput[i]=bufin.readLine();
			len[i]=strInput[i].length();
			file.write((strInput[i]+"\n").getBytes());
		}
		while(true) 
		{
			fp=0;
			file.seek(0);
			System.out.print("你要显示第几行?"+"(1--6) ");
			lineNo=Integer.parseInt(bufin.readLine());
			for(int i=1;i<lineNo;i++)
            	fp=fp+(long)len[i-1]+1;
		    file.seek(fp);
			System.out.println("第"+lineNo+"行"+":"+file.readLine());
			System.out.println("继续吗?"+"(y/n)");
			if((bufin.readLine().equals("n"))) 
			   break;
		}
		file.close();
	}
} 

⌨️ 快捷键说明

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