Java RandomAccessFile?÷?
???????????? ???????[ 2014/10/29 10:05:19 ] ????????Java ???? ????
?????????????
????????????????????????????Щ???????????????????????????????????????????????????????????????棬??????????????????????????????????????????????????????
????fileChannel.map(FileChannel.MapMode mode?? long position?? long size)??????????????????????????С???????????????????????????λ??????????????Χ???ж????????????????????????????????С????
????MappedByteBuffer??ByteBuffer???????????????? ByteBuffer?????з?????????????force()???????????????????μ??洢?豸?????load()???洢?豸?е?????????????С? isLoaded()λ??????е??????????洢????????????????????????????put()??get()?????????????????????? asCharBuffer( )???????????????????????????????????????????д?????????????
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
public class LargeMappedFiles {
static int length = 0x8000000; // 128 Mb
public static void main(String[] args) throws Exception {
// ?????????д??????????????????RandomAccessFile???????????
FileChannel fc = new RandomAccessFile("test.dat"?? "rw").getChannel();
//???????????????д??????????????????д????????
MappedByteBuffer out = fc.map(FileChannel.MapMode.READ_WRITE?? 0?? length);
//д128M??????
for (int i = 0; i < length; i++) {
out.put((byte) 'x');
}
System.out.println("Finished writing");
//???????м?6?????????
for (int i = length / 2; i < length / 2 + 6; i++) {
System.out.print((char) out.get(i));
}
fc.close();
}
}
???????????д???????FileOutputStream?????????????е???????? ???????RandomAccessFile?????????????????????FileInputStream??д??????????????????????????????д?????????ɡ?
?????ó??????????128Mb????????????????????????????????????????????????????????£????????????????????????????е??С??????????????????????????????????????????????????????(??????2 GB)?????Java????ò???????"?????????"????????????
????RandomAccessFile???????
/*
* ????????????RandomAccessFile??????????????????????????????
*/
package com.lwj.demo;
import java.io.*;
public class RandomAccessFileDemo {
public static void main(String[] args) throws Exception {
RandomAccessFile file = new RandomAccessFile("file"?? "rw");
// ??????file?????д????
file.writeInt(20);// ?4?????
file.writeDouble(8.236598);// ?8?????
file.writeUTF("???????UTF?????");// ???????д??????????????????????????readShort()???
file.writeBoolean(true);// ?1?????
file.writeShort(395);// ?2?????
file.writeLong(2325451l);// ?8?????
file.writeUTF("???????UTF?????");
file.writeFloat(35.5f);// ?4?????
file.writeChar('a');// ?2?????
file.seek(0);// ????????λ???????????????
// ???′?file????ж?????????????????λ??
System.out.println("——————??file??????λ???????——————");
System.out.println(file.readInt());
System.out.println(file.readDouble());
System.out.println(file.readUTF());
file.skipBytes(3);// ????????????3???????????м??????????boolean???short???
System.out.println(file.readLong());
file.skipBytes(file.readShort()); // ?????????“???????UTF?????”??????????readShort()?????????????????????ü?2??
System.out.println(file.readFloat());
//?????????????????
System.out.println("——————??????????file??fileCopy??——————");
file.seek(0);
RandomAccessFile fileCopy=new RandomAccessFile("fileCopy"??"rw");
int len=(int)file.length();//??????????????????
byte[] b=new byte[len];
file.readFully(b);
fileCopy.write(b);
System.out.println("????????");
}
}
RandomAccessFile ????д?????
/**
*
* @param skip ??????????????в???????
* @param str ???????????
* @param fileName ???·??
*/
public static void beiju(long skip?? String str?? String fileName){
try {
RandomAccessFile raf = new RandomAccessFile(fileName??"rw");
if(skip < 0 || skip > raf.length()){
System.out.println("???????????Ч");
return;
}
byte[] b = str.getBytes();
raf.setLength(raf.length() + b.length);
for(long i = raf.length() - 1; i > b.length + skip - 1; i--){
raf.seek(i - b.length);
byte temp = raf.readByte();
raf.seek(i);
raf.writeByte(temp);
}
raf.seek(skip);
raf.write(b);
raf.close();
} catch (Exception e) {
e.printStackTrace();
}
}
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????