语言: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; } }
}
}