1 Star 11 Fork 11

charjay / distributed

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
FileInputProgram.java 776 Bytes
一键复制 编辑 原始数据 按行查看 历史
charjay 提交于 2018-08-18 15:22 . io
package com.charjay.nio.channel;
import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class FileInputProgram {
static public void main( String args[] ) throws Exception {
FileInputStream fin = new FileInputStream("c:\\test.txt");
// 获取通道
FileChannel fc = fin.getChannel();
// 创建缓冲区
ByteBuffer buffer = ByteBuffer.allocate(1024);
// 读取数据到缓冲区
fc.read(buffer);
buffer.flip();
while (buffer.remaining() > 0) {
byte b = buffer.get();
System.out.print(((char)b));
}
fin.close();
}
}
1
https://gitee.com/charjay/distributed.git
git@gitee.com:charjay/distributed.git
charjay
distributed
distributed
master

搜索帮助