package Test;
import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class MyTest {
public static void main(String[] args) {
try(FileInputStream aFile = new FileInputStream(MyTest.class.getResource("/my-config.xml").getFile())) {
FileChannel fileChannel = aFile.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(48);
int bytesRead = fileChannel.read(buffer);
while(bytesRead != -1){
buffer.flip();
while(buffer.hasRemaining()){
System.out.print((char)buffer.get());
}
buffer.clear();
bytesRead = fileChannel.read(buffer);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Java FileChannel 示例
最新推荐文章于 2022-11-16 01:20:19 发布