Skip to content

Instantly share code, notes, and snippets.

@suatatan
Created December 7, 2015 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suatatan/23b8745869f37a19b9fa to your computer and use it in GitHub Desktop.
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:
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