Skip to content

Instantly share code, notes, and snippets.

@Tang8330
Created March 27, 2023 04:38
Show Gist options
  • Save Tang8330/84ca7274a22d97ce4de497a7b97d08ae to your computer and use it in GitHub Desktop.
Save Tang8330/84ca7274a22d97ce4de497a7b97d08ae to your computer and use it in GitHub Desktop.
Test Java PropertiesFile
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