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.

Source: Internet
Author: User

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 ();}}


 

 

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.