Java-->一个只能运行十次的程序

--> 感觉没什么营养的样子啊...

package com.dragon.java.tensoftware;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/*
 * 编写一个程序, 该程序只能--运行--10次, 每次运行时提示剩余次数, 10次之后提示已到期
 */
public class Test {
    public static void main(String[] args) throws IOException {
        BufferedReader br = null;
        FileWriter fw = null;
        try {
            br = new BufferedReader(
                    new FileReader(
                            "C:/Users/xy/Desktop/文件/Java/Java/DailyCode/08-14/src/com/dragon/java/times.txt")); // 定义输入流,
            int times = Integer.parseInt(br.readLine()); // 读取一行数据, 转为int值

            if (times > 0) {
                System.out.println("欢迎使用--十次崩--软件, 剩余使用次数: " + times);
                fw = new FileWriter(
                        "C:/Users/xy/Desktop/文件/Java/Java/DailyCode/08-14/src/com/dragon/java/times.txt"); // 定义输出流,
                fw.write(--times + ""); // 将次数减1, 写回文件中,将次数写回文件时转为String 类型
            } else {
                System.out.println("软件已到期");
            }
        } catch (IOException e) {
            System.out.println(e);
        } finally {
            try {
                br.close();
                fw.close();
            } catch (IOException e) {
                System.out.println(e);
            }
        }
    }
}

--> 果然不能坐在床上玩电脑... 腰好痛...

posted on 2016-08-14 17:27  西门吃雪  阅读(506)  评论(0编辑  收藏  举报

导航