Created
March 29, 2019 07:40
-
-
Save Terkea/6fecc6151e1835ae19a0c0f82ff8d343 to your computer and use it in GitHub Desktop.
Java properties example
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 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