IO Properties Instance

Source: Internet
Author: User
Package com.zyf.day22;
Import Java.io.File;
Import Java.io.FileInputStream;
Import Java.io.FileOutputStream;
Import java.io.IOException;

Import java.util.Properties; Requirements: Use properties to achieve the software can only run three times, more than three times after the prompt to purchase genuine, back JVM public class Demo5 {public static void main (string[] args) throws IO
		Exception {File File = new file ("C:\\count.properties");
		if (!file.exists ()) {file.createnewfile ();
		//Create Properties Object properties = new properties ();
		Load the information of the configuration file into the properties Properties.load (new FileInputStream (file)); int count = 0;
		Defines the number of times that the variable is used to save the running times of the software. String value = Properties.getproperty ("Count");
		if (value!=null) {count = Integer.parseint (value);
			//Judge if the number of times used has reached three if (count = 3) {System.out.println ("You have used the software has been used three times, please purchase genuine software");
		System.exit (0);
		} count++;
		SYSTEM.OUT.PRINTLN ("You have used the software" + Count + "Times");
		Properties.setproperty ("Count", Count + "");
Use properties to generate a configuration file Properties.store (new FileOutputStream (file), "Runtime");	}
}
 

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.