public class CountDemo {
public static void main(String[] args) {
if(! checkLogin()){
System.out.println("Sorry, you cann't login .");
System.exit(0);
}
System.out.println("Welcome ..");
}
private static boolean checkLogin() {
// TODO Auto-generated method stub
FileReader fr = null;
File file = null;
FileWriter fw = null;
BufferedWriter bw = null;
try {
file = new File("setup.ini");
if(!file.exists()){
file.createNewFile();
}
fr = new FileReader("setup.ini");
Properties pro = new Properties();
pro.load(fr);
int key = 0;
if(pro.getProperty("count") != null){
String p = pro.getProperty("count");
key = Integer.parseInt(p) + 1;
if(key > 5){
return false;
}
}else{
key = 1;
}
pro.setProperty("count", String.valueOf(key));
fw = new FileWriter("setup.ini");
bw = new BufferedWriter(fw);
String comments = "You logined : ";
pro.store(bw, comments);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(fr != null){
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(bw != null){
try {
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(fw != null){
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return true;
}
} |
|