专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »博文摘选 » java读取文件:JAVA读取大文件操作 »正文

java读取文件:JAVA读取大文件操作

来源: 发布时间:星期日, 2009年9月27日 浏览:65次 评论:0

 public static void main(String[] args) throws Exception {
    int bufSize = 1024;
    byte[] bs = new byte[bufSize];
    ByteBuffer byteBuf = ByteBuffer.allocate(1024);
    FileChannel channel = new RandomAccessFile("d:\\filename","r").getChannel();
    while(channel.read(byteBuf) != -1) {
      int size = byteBuf.position();
      byteBuf.rewind();
      byteBuf.get(bs);
      // 把文件当字符串处理,直接打印做为一个例子。
      System.out.print(new String(bs, 0, size));
      byteBuf.clear();
    }
  }

0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: