filedemo.java
来自「实现了《算法设计与分析》的一次课后题」· Java 代码 · 共 51 行
JAVA
51 行
import java.io.*;
public class filedemo {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args)throws
IOException {
try{
FileReader filereader=new FileReader("D:\\wenjian.txt");
BufferedReader reader=new BufferedReader(filereader);
String s="";
while((s=reader.readLine())!=null){//掌握这种输入方法
String[] str=s.split(" ");
for(int l=0;l<str.length;l++)
{ int a=Integer.valueOf(str[l]);
System.out.println(a);}
}
}catch(FileNotFoundException e){
System.err.println("文件没有找到!");
System.exit(0);
}
RandomAccessFile rf=new RandomAccessFile("D:\\input.txt","rw");
/**FileInputStream rt=new FileInputStream("D:\\input.txt");
try{
DataInputStream r=new DataInputStream(rt);
System.out.println(r.readDouble());
rt.close();
r.close();
}catch(EOFException e){
throw new EOFException();
}*/
for(int i=0;i<10;i++)
rf.writeDouble(i*1.414);
rf.close();
rf=new RandomAccessFile("D:\\input.txt","rw");
rf.seek(5*8);
rf.writeDouble(47.0001);
rf.close();
rf=new RandomAccessFile("D:\\input.txt","r");
for(int i=0;i<10;i++)
System.out.println("value"+i+":"+rf.readDouble());
rf.close();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?