File file = new File("oppo.in");
File file1 = new File("main.in");
GregorianCalendar gc =new GregorianCalendar();
SimpleDateFormat sf =new SimpleDateFormat("yyyyMMdd");
if(!file.exists())
{
try {
file.createNewFile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Date d=new Date();
String aa=sf.format(d);
byte bt[] = new byte[1024];
bt = aa.getBytes();
try {
FileOutputStream in = new FileOutputStream(file);
try {
in.write(bt, 0, bt.length);
in.close();
// boolean success=true;
// System.out.println("写入文件成功");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else{
Date d=null;
Date d2 = null;
d=new Date();
String str1="";
try {
FileInputStream in=new FileInputStream(file);
// size 为字串的长度 ,这里一次性读完
int size=in.available();
byte[] buffer=new byte[size];
in.read(buffer);
in.close();
str1=new String(buffer,"GB2312");
} catch (Exception e1) {
// TODO: handle exception
}
try {//字符串转换为时间
d2 = sf.parse(str1);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
gc.setTime(d);
String s1=sf.format(gc.getTime());
try {
d=sf.parse(s1);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
long tt=d.getTime()-d2.getTime();
long days = tt/ (1000 * 60 * 60 * 24);//计算时间
System.out.println(days);
if(days>=30){
String str="";
int password;
String str11="";
String a = "";
try {
FileInputStream in=new FileInputStream(file1);
// size 为字串的长度 ,这里一次性读完
int size=in.available();
byte[] buffer=new byte[size];
in.read(buffer);
in.close();
str=new String(buffer,"GB2312");
password=Integer.parseInt(str)*Integer.parseInt(str)*Integer.parseInt(str);
str11=password+"";
a=str11.substring(0,3);
} catch (Exception e1) {
// TODO: handle exception
}
byte bt[] = new byte[1024];
bt = a.getBytes();
try {
FileOutputStream in = new FileOutputStream(file1);
try {
in.write(bt, 0, bt.length);
in.close();
// boolean success=true;
// System.out.println("写入文件成功");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Date d1=new Date();
String aa=sf.format(d1);
byte bt1[] = new byte[1024];
bt1 = aa.getBytes();
try {
FileOutputStream in = new FileOutputStream(file);
try {
in.write(bt1, 0, bt1.length);
in.close();
// boolean success=true;
// System.out.println("写入文件成功");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}