import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class javatest
{
long getInt(byte[] datas)
{
// TODO Auto-generated method stub
ByteBuffer temp = ByteBuffer.allocate(datas.length);
temp.put(datas);
temp.flip();
return temp.getLong();
}
public static void main(String[] args) throws IOException
{
// byte [] bbuf = new byte[] {0x00,0x00,0x00,0x01};
// javatest jt= new javatest();
// long a = jt.getInt(bbuf);
//
// System.out.println(“a”+ a);
FileChannel fc = new FileOutputStream(“a.txt”).getChannel();
fc.write(ByteBuffer.wrap(“this is test”.getBytes()));
fc.close();
fc = new RandomAccessFile(“a.txt”, “rw”).getChannel();
fc.position(fc.size());//到最后位置然后 后面的byte加到后面
fc.write(ByteBuffer.wrap(“Some more”.getBytes()));
fc.close();
fc = new FileInputStream(“a.txt”).getChannel();
ByteBuffer buff = ByteBuffer.allocate(100);
fc.read(buff);
buff.flip();
while (buff.hasRemaining()) {// 是否到达限定的位置
System.out.println((char) buff.get());
}
}
}