package random;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
public class RandomIOImpl {
public static void main(String[] arges){
File file = new File("c:\\测试\\a.txt");
RandomAccessFile raf = null;
RandomAccessFile raf1 = null;
try {
raf = new RandomAccessFile(file,"rw");
byte[] temp = new byte[1000];
raf.read(temp,100,200);
File file1 = new File("c:\\测试\\c.txt");
if(!file1.exists()){
file.createNewFile();
}
raf1 = new RandomAccessFile(file1,"rw");
raf1.write(temp,100,180);
raf.close();
raf1.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
public class RandomIOImpl {
public static void main(String[] arges){
File file = new File("c:\\测试\\a.txt");
RandomAccessFile raf = null;
RandomAccessFile raf1 = null;
try {
raf = new RandomAccessFile(file,"rw");
byte[] temp = new byte[1000];
raf.read(temp,100,200);
File file1 = new File("c:\\测试\\c.txt");
if(!file1.exists()){
file.createNewFile();
}
raf1 = new RandomAccessFile(file1,"rw");
raf1.write(temp,100,180);
raf.close();
raf1.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
本文介绍了一个Java程序示例,演示了如何使用RandomAccessFile类从一个文件中读取部分数据,并将这些数据写入到另一个文件中。具体操作包括创建文件、读取指定范围的数据以及将数据写入新文件。
4177

被折叠的 条评论
为什么被折叠?



