📄 randomread.java
字号:
//randomRead.Java
import java.io.*;
public class randomRead
{
public static void main(String args[]) throws IOException{
System.out.println("Please enter a directory that the file located in:");
StringBuffer stfDir = new StringBuffer();
char ch;
while(( ch=(char) System.in.read())!='\n')
{
stfDir.append(ch);
}
File dir = new File(stfDir.toString());
System.out.println("Please enter a filename that want to read:");
StringBuffer stfFilename = new StringBuffer();
char c;
while((c = (char)System.in.read())!='\n')
{
stfFilename.append(ch);
}
File readFrom = new File(dir,stfFilename.toString());
if(readFrom.isFile() && readFrom.canWrite() && readFrom.canRead())
{
RandomAccessFile rafFile =new RandomAccessFile(readFrom,"rw");
while(rafFile.getFilePointer()<rafFile.length())
System.out.println(rafFile.readLine());
rafFile.close();
}
else
System.out.println("File cann't be read!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -