Created
December 7, 2015 18:51
-
-
Save suatatan/23b8745869f37a19b9fa to your computer and use it in GitHub Desktop.
Java’daki bu özellik sayesinde daha sonra değiştirebileceğiniz verileri kodun içerisine değil property dosyasında saklayıp oradan çağırarak okuyabilirsiniz. Bir nevi kofigürasyon dosyası yani. IDE kullandığınızı varsayarak try’ler ve importlardan hariç kodları paylaşıyorum:
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
Properties prop = new Properties(); | |
OutputStream output = null; | |
//Property dosyasının yazılacağı yer: | |
output = new FileOutputStream("config.properties"); | |
//property değişkenlerini tanımlıyoruz: | |
prop.setProperty("database", "localhost"); | |
prop.setProperty("dbuser", "mkyong"); | |
prop.setProperty("dbpassword", "password"); | |
//property'i kaydediyoruz. | |
prop.store(output, null); | |
//sonuçta propery | |
//Çağırmak isteyince de aşağıdaki gibi çağırıyoruz. | |
input = new FileInputStream("config.properties"); | |
// yüklüyoruzz | |
prop.load(input); | |
//database parametresini çağırıyoru. | |
System.out.println(prop.getProperty("database")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment