9月3日作业

语言:java

package com.briup.ch11;

import java.io.*;
import java.util.Scanner;

/**
 * @author 23982
 */
public class Work8 {
    public static void main(String[] args) throws IOException {
        String path = "src/com/briup/ch11/File.txt";
        String dir = "src/com/briup/ch11/";
        Scanner scanner = new Scanner(System.in);
        int count = 3;
        String input = "试用一次";
        int i = 0;
        int j;
        System.out.println("可免费使用"+count+"次,输入“试用一次”进行使用");
        while (true) {
            if (i >= 0 && i < count) {
                if (input.equals(scanner.nextLine())) {
                    String d = String.valueOf(i++)+".txt";
                    System.out.println("使用成功,剩余使用次数:"+(count - i));
                    FileReader fr = new FileReader(path);
                    BufferedReader br = new BufferedReader(fr);
                    BufferedWriter bw = new BufferedWriter(new FileWriter(new File(dir, d)));
                    while ((j = br.read()) != -1) {
                        bw.write(j);
                    }
                    bw.close();
                    br.close();
                }
                else {
                    System.out.println("请输入正确字符:");
                    scanner.nextLine();
                }

            }else {
                System.out.println("试用次数结束,请付费!");
                break;
            }
        }

}

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值