Properties 파일 관리에 3가지 방법이 있다.
Properties 사용 이유
유의 사항
구현 방법 (1번 방식)
// Java
// Option 1. File Path Load
File file = new File("$DIRECTORY", "$FILE_NAME");
if(!file.exists()){ return ""; }
// Option 2. Assets
Resources resources = context.getResources();
AssetManager assetManager = resources.getAssets();
try {
Properties properties = new Properties();
// Option 1. File Path Load
FileInputStream fis = new FileInputStream(file);
properties.load(fis);
// Option 2. Assets
InputStream inputStream = assetManager.open("$FILE_NAME");
properties.load(inputStream);
properties.getProperty("$KEY", "");
} catch (IOException e) {
Log.i("Properties", "No properties available");
}
// Option 1. File Path Load
val file = File("$DIRECTORY", "$FILE_NAME")
if(!file.exists()){ return }
// Option 2. Assets
val resources = context.getResources()
val assetManager = resources.assets
try {
val properties = Properties()
// Option 1. File Path Load
val fis = FileInputStream(file)
properties.load(fis)
// Option 2. Assets
val inputStream = assetManager.open("$FILE_NAME")
properties.load(inputStream);
properties.getProperty("$KEY", "")
} catch (ex : Exception) {
Log.i("Properties", "No properties available")
}
구현 방법 (2번 방식)