Skip to content

Instantly share code, notes, and snippets.

@Terkea
Created March 29, 2019 07:40
Show Gist options
  • Save Terkea/6fecc6151e1835ae19a0c0f82ff8d343 to your computer and use it in GitHub Desktop.
Save Terkea/6fecc6151e1835ae19a0c0f82ff8d343 to your computer and use it in GitHub Desktop.
Java properties example
package app.model;
import java.io.*;
import java.util.Properties;
public class PropertiesFile {
public static Properties prop = new Properties();
public void saveProperty(String name, String value){
try {
prop.setProperty(name, value);
InputStream file = getClass().getResourceAsStream("config.terkea");
prop.store(new FileOutputStream("config.terkea"), null);
} catch (IOException e) {
e.printStackTrace();
}
}
public void deletePropety(String name){
try {
prop.remove(name);
InputStream file = getClass().getResourceAsStream("config.terkea");
prop.store(new FileOutputStream("config.terkea"), null);
} catch (IOException e) {
e.printStackTrace();
}
}
public String getProp(String name){
try {
prop.load(new FileInputStream("config.terkea"));
String value = prop.getProperty(name);
return value;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment