java的字节的数组的交换思想及输入输出流的小项目

当我们下载一个试用版软件,没有购买正版的时候,每执行一次就会
提醒我们还有多少次使用机会,用学过的IO流知识,模拟试用版软件,试用
10次机会,执行一次就提示一次您还有几次机会,如果次数到了提示请购买正版

package day22;

import java.io.*;

public class homework2 {
    public static void main(String[] args) {
        try {
            //ou.write("9".getBytes());
             //ou.flush();
            File file=new File("5.text");
            if (!file.exists()){
                BufferedOutputStream ou=new BufferedOutputStream(new FileOutputStream("5.text"));
                ou.write("10".getBytes());
                ou.close();
            }
            BufferedInputStream in1= new BufferedInputStream(new FileInputStream("5.text"));
            byte[] c=new byte[10];
            int len=(char)in1.read(c);
            char[]d=new char[len];
            for (int i=0;i<len;i++){
                d[i]=(char)c[i];
            }
            int count=Integer.valueOf(String.valueOf(d));
            if (count>1){
                in1.close();
                BufferedOutputStream ou=new BufferedOutputStream(new FileOutputStream("5.text"));
                count--;
                ou.write((count+"").getBytes());
                ou.flush();
                System.out.println("你还有"+count+"次机会");
            }
            else {
                System.out.println("您需要购买");
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

}
代码要考虑它的周全性
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值