标题:为什么我将10个数存入记事本,但是读出来出现错误
取消只看楼主
腹黑伸手党
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-10-27
结帖率:100%
已结贴  问题点数:20 回复次数:0 
为什么我将10个数存入记事本,但是读出来出现错误
如题,输入 1 2 3 4 5 6 7 8 9 0的时候,记事本里显示了这几个数是对的,但读取时就变了。。。
程序代码:
import *;
public class Idu{
    public static void main(String[] args ) throws IOException{
        DataOutputStream out = new DataOutputStream(new FileOutputStream("gb.txt"));
        int units;
        long p;
        for( int i = 0;i<10;i++){
            System.out.println("输入第"+(i+1)+"个数:");
            units = System.in.read();
            p = System.in.read();
            p = System.in.read();
            out.writeInt(units);   
        }
        out.close();
   
        DataInputStream in = new DataInputStream(new FileInputStream("gb.txt"));
        int unit;
        for( int i = 0;i<10;i++){
            unit = in.readInt();
            System.out.println(unit);
        }
        in.close();
    }
}
            

            


[ 本帖最后由 腹黑伸手党 于 2012-10-29 12:59 编辑 ]
搜索更多相关主题的帖子: 记事本 
2012-10-29 12:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-384834-1-1.html




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

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