当我们下载一个试用版软件,没有购买正版的时候,每执行一次就会
提醒我们还有多少次使用机会,用学过的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();
}
}
}
代码要考虑它的周全性