我想对一个A文件进行操作,如A文件大小为2M。
我想从第2k的位置开始写1K的内容。
FileInputStream fileIn = new FileInputStream("test.tmp");
byte[] readData = new byte[1*1024];
fileIn.read(readData);
File reTempFile = null;
reTempFile = new File(path+"test.temp");
if(reTempFile.exists()){
FileOutputStream fileOut = new FileOutputStream(reTempFile);
fileOut.write(readData,0,readData.length);
fileOut.flush();
fileOut.close();
System.out.println(readData.length);
}
我这样写的话,是可以写进去,但是test.tmp也从原来的1M大小变成1K了
我想从第2k的位置开始写1K的内容。
FileInputStream fileIn = new FileInputStream("test.tmp");
byte[] readData = new byte[1*1024];
fileIn.read(readData);
File reTempFile = null;
reTempFile = new File(path+"test.temp");
if(reTempFile.exists()){
FileOutputStream fileOut = new FileOutputStream(reTempFile);
fileOut.write(readData,0,readData.length);
fileOut.flush();
fileOut.close();
System.out.println(readData.length);
}
我这样写的话,是可以写进去,但是test.tmp也从原来的1M大小变成1K了
int length = 10*m;
File file = new File("1.txt");
//file.length();
MappedByteBuffer mb = new RandomAccessFile(file,"rw").getChannel().map(FileChannel.MapMode.READ_WRITE, file.length()/2,length);
for(int i=0; i<length; i++){
mb.put((byte)'x');
}