| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 451 人关注过本帖
标题:while((remain = fileInputStream.read()) != -1)
只看楼主 加入收藏
yu1543054075
Rank: 1
等 级:新手上路
帖 子:102
专家分:8
注 册:2015-4-30
结帖率:90.24%
收藏
已结贴  问题点数:20 回复次数:3 
while((remain = fileInputStream.read()) != -1)
import *;
public class FileStreamDemo {
    public static void main(String[] args) {
        try {
            byte[] buffer = new byte[1024];
            FileInputStream fileInputStream =
            new FileInputStream(new File(args[0]));
            FileOutputStream fileOutputStream =
            new FileOutputStream(new File(args[1]));
            System.out.println("复制档案:" +
            fileInputStream.available() + "字节");
            while(true) { // 从来源档案读取数据至缓冲区
                if(fileInputStream.available() < 1024) {
                    int remain;
                    while((remain = fileInputStream.read())
                    != -1) {
                        fileOutputStream.write(remain);
                    }
                    break;
                }
                else {
                    fileInputStream.read(buffer);
                    // 将数组数据写入目的档案
                    fileOutputStream.write(buffer);
                }
            }
            // 关闭串流
            fileInputStream.close();
            fileOutputStream.close();
            System.out.println("复制完成");
        }
        catch(ArrayIndexOutOfBoundsException e) {
            System.out.println(
            "using: java FileStreamDemo src des");
            e.printStackTrace();
        }
        catch(IOException e) {
            e.printStackTrace();
        }
    }
}
 int remain;
while((remain = fileInputStream.read())!= -1)
不明白是什么意思,求指导!!!
搜索更多相关主题的帖子: public import 
2015-06-14 20:55
秦时的明月夜
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:13
帖 子:126
专家分:504
注 册:2013-3-12
收藏
得分:10 
文件读取……=-1,就是读到文件结束了……没有就是继续……
2015-06-15 07:53
日知己所无
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:38
帖 子:427
专家分:2071
注 册:2014-3-22
收藏
得分:10 
FileInputStream.read()的API文档里是这么说的:

Returns:the next byte of data, or -1 if the end of the file is reached.
返回值:下一个字节的数据,或者-1(代表文件结束了)

http://docs.
2015-06-19 22:34
日知己所无
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:38
帖 子:427
专家分:2071
注 册:2014-3-22
收藏
得分:0 
在官网上,找到了中文的API说明

返回:下一个数据字节;如果已到达文件末尾,则返回 -1。

http://download.()
2015-06-19 22:40
快速回复:while((remain = fileInputStream.read()) != -1)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016168 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved