The examples in this article mainly implement Java reading and writing ini files. The details are as follows, and detailed comments are included in the code.
In Java, configuration files generally have two main forms: xml file or property file. But most people are accustomed to using ini files, and the sectioning and annotation functions of ini files are also easy to understand and use compared to xml.
Example code:
package ; import ; import ; import ; import ; public class IniFileOpration { public static void main(String[] args) { try { //Storage location of ini file String filepath = "D:\\"; //Create file input stream FileInputStream fis = new FileInputStream(filepath); //Create file output stream OutputStream opt = null; //Create Properties property object to receive properties in ini file Properties pps = new Properties(); //Load attributes from file stream (fis); //Get the corresponding value of the key through getProperty ("property name") (("url1")); (("url11")); //Load the read file stream opt = new FileOutputStream(filepath); // Assigning the value of the same key will be overwritten by settingProperty(key,value) ("url2", "v2"); ("url1", "v1"); //Modify the value (essential) (opt, null); (); } catch (Exception e) { (); } } }
Summarize
The above is all about Java reading and writing ini file code examples, I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!