????????RandomAccessFile???????????????????????????????????????????????飬????ò??????????????????????????????????д????????????????????????????????????????????????н??з?飬???д??
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* ????????????????????д????
*/
public class Test {
public static void main(String[] args) throws Exception {
// ???????????????????????л???????????С?????
RandomAccessFile raf = new RandomAccessFile("D://abc.txt"?? "rw");
raf.setLength(1024*1024); // ????? 1M ????????
raf.close();
// ???д??????????
String s1 = "??????????";
String s2 = "??????????";
String s3 = "???????????";
String s4 = "??????????";
String s5 = "??????????";
// ??????????д????????
new FileWriteThread(1024*1??s1.getBytes()).start(); // ???????1024???????д??????
new FileWriteThread(1024*2??s2.getBytes()).start(); // ???????2048???????д??????
new FileWriteThread(1024*3??s3.getBytes()).start(); // ???????3072???????д??????
new FileWriteThread(1024*4??s4.getBytes()).start(); // ???????4096???????д??????
new FileWriteThread(1024*5??s5.getBytes()).start(); // ???????5120???????д??????
}
// ?????????????????λ??д?????????
static class FileWriteThread extends Thread{
private int skip;
private byte[] content;
public FileWriteThread(int skip??byte[] content){
this.skip = skip;
this.content = content;
}
public void run(){
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile("D://abc.txt"?? "rw");
raf.seek(skip);
raf.write(content);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
raf.close();
} catch (Exception e) {
}
}
}
}
}