File file = new File("d:"+File.separator+"test.txt");
FileInputStream input = null;
input = new FileInputStream(file);
FileChannel fin = null;
fin = input.getChannel();
MappedByteBuffer mbb = null;
mbb = fin.map(FileChannel.MapMode.READ_ONLY,0,file.length());
byte data[] = new byte[(int)file.length()];
int foot = 0;
while(mbb.hasRemaining())
data[foot ++] = mbb.get();
System.out.println(new String(data));
fin.close();
input.close();
转载于:https://my.oschina.net/liangxiao/blog/126261