Dark Horse Programmer -- java -- gets the number of times an application is running. If it exceeds 5 times, a prompt indicating that the number of Use Times has reached the registration level should be provided, and the program should not be run again.
Obtain the number of times an application is running. If it exceeds 5 times, a prompt is displayed indicating that the application has been registered. Do not run the program again.
Import java. io. file; import java. io. fileInputStream; import java. io. fileOutputStream; import java. io. IOException; import java. util. properties; public class Test5 {public static void main (String [] args) throws Exception {getAppCount ();} private static void getAppCount () throws Exception {File file = new File ("C: \ Users \ Administrator \ Desktop \ test folder", "B .txt"); if (! File. exists () file. createNewFile (); FileInputStream FCM = new FileInputStream (file); Properties pro = new Properties (); pro. load (FCM); String value = pro. getProperty ("name"); int count = 0; if (value! = Null) {count = Integer. parseInt (value); if (count> = 5) {throw new RuntimeException ("used") ;}} count ++; pro. setProperty ("name", count + ""); FileOutputStream fos = new FileOutputStream (file); pro. store (fos, ""); fos. close (); FCM. close ();}}