1. Create a method to run the program
2 The Main method determines whether the number of arrivals to end the trial of the program
3 separate creation method for judging conditions
4. In the judging condition method:
4.1 Create a configuration file that holds the program information, of course, it is empty at this time
4.2 Creating a Property object
4.3 Create a string-type value Reference object and give it a key-worthy method in the Property object
4.4 Add a counter int count = 0; This counter is useful for the first time the program runs, and there is no information for that counter in the configuration file
4.5 To determine whether value is empty, if so, jump directly to the next line of code that is the counter increment; if it is not, we will take the value of the counter in the configuration file and assign it to count in memory, and
To determine if the counter meets the number of times required, and if it satisfies the return true to end the program
4.6 Counter self-increment
4.7 Calling the Set key value method in the Properties object
4.8 Setting a path to the output stream for the profile
4.9 Call the storage method in the properties object to store the counter information.
Counter is difficult ah ... PS: Think of a half-day look
Package com.java.Procedure.www;
Import Java.io.File;
Import Java.io.FileInputStream;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.InputStream;
Import java.util.Properties;
public class Proceduredmeo {
public static void Main (string[] args) throws IOException {
Determine whether the number of program runs reached the trial count
if (Isstop ()) {
System.out.println ("The number of uses has arrived, please register");
Return
}
Start the program
Procedurerun ();
}
/**
* Store the number of runs and determine if the maximum number of arrivals
* @return
* @throws IOException
*/
private static Boolean Isstop () throws IOException {
Creating a configuration file
File Configfile=new file ("D:\\ja\\app.properties");
Judgment exists not
if (!configfile.exists ()) {
Configfile.createnewfile ();
}
Create an output stream
FileInputStream fis=new FileInputStream (configfile);
Creating properties
Properties Prop=new properties ();
Load
Prop.load (FIS);
String Value=prop.getproperty ("Count");
int count = 0;//as a token it is the first time that the program is run for the second time because this is no longer used when the property set is called
if (value!=null) {
Count=integer.parseint (value);
if (count>6) {
return true;
}
}
count++;
Prop.setproperty ("Count", integer.tostring (count));//Set properties
FileOutputStream fos=new FileOutputStream (configfile);//Set Output stream
Intrinsic
Prop.store (FOS, "Properties");
Mathematic
Fis.close ();
Fos.close ();
return false;
}
/**
* Program Run
* @param file
* @throws IOException
*/
private static void Procedurerun () {
SYSTEM.OUT.PRINTLN ("Program startup Run");
}
}
Total process of program trial count