Created
March 27, 2023 04:38
-
-
Save Tang8330/84ca7274a22d97ce4de497a7b97d08ae to your computer and use it in GitHub Desktop.
Test Java PropertiesFile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package propertiesfile; | |
import java.io.FileOutputStream; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.util.Properties; | |
public class PropertyFileReading { | |
public static void main(String[] args) { | |
Properties prop = new Properties(); | |
try { | |
// load a properties file for reading | |
prop.load(new FileInputStream("/tmp/application.properties")); | |
// get the properties and print | |
prop.list(System.out); | |
prop.setProperty("foo", "'\n'"); | |
//Reading each property value | |
System.out.println(prop.getProperty("FileName")); | |
System.out.println(prop.getProperty("Author_Name")); | |
System.out.println(prop.getProperty("Website")); | |
System.out.println(prop.getProperty("TOPIC")); | |
prop.store(new FileOutputStream("/tmp/application.properties"), null); | |
} catch (IOException ex) { | |
ex.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment