用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

Java read()方法

2015-04-12 作者: java源代码大全举报

[java]代码库

/**
 * read()方法
 * Reads a byte of data from this input stream. This method blocks
 * if no input is yet available.
 * 返回值 the next byte of data, or <code>-1</code> if the end of the file is reached.
 * <p/>
 * 该函数返回一个int类型,范围从0至255,如果到达流末尾,返回-1。
 * 通过ByteArrayInputStream的源码可以看到是如何从byte转到int
 * public synchronized int read() {
 *      return (pos < count) ? (buf[pos++] & 0xff) : -1;
 * }
 */
@Test
public void test1() throws Exception {
    FileInputStream in = new FileInputStream("E:\\key\\test.txt");
    FileOutputStream out = new FileOutputStream("E:\\key\\test2.txt");

    /**
     * 返回值为下一个字节,如果没有数据,返回-1
     */
    int temp;
    while ((temp = in.read()) != -1) {
        /**
         * 参数: the byte to be written.
         */
        out.write(temp);
    }
}//源代码片段来自云代码http://yuncode.net
			


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...