Chinaunix首页 | 论坛 | 博客
  • 博客访问: 377252
  • 博文数量: 85
  • 博客积分: 1504
  • 博客等级: 上尉
  • 技术积分: 928
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-04 12:20
文章分类

全部博文(85)

文章存档

2011年(66)

2010年(19)

分类: Java

2011-01-21 16:47:41

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class FileByteTest {
    public static void main(String[] args) throws IOException {

        BufferedInputStream in = new BufferedInputStream(new FileInputStream(
                "C:/Test.java"));
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);

        System.out.println("Available bytes:" + in.available());

        byte[] temp = new byte[1024];
        int size = 0;
        while ((size = in.read(temp)) != -1) {
            out.write(temp, 0, size);
        }
        in.close();

        byte[] content = out.toByteArray();
        System.out.println("Readed bytes count:" + content.length);
    }
}
阅读(1966) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-03-07 13:43:23

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com