Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mpen
Created November 9, 2009 05:10
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 mpen/229709 to your computer and use it in GitHub Desktop.
Save mpen/229709 to your computer and use it in GitHub Desktop.
java.util.Properties load/store, get/set
// java.util.Properties load/store, get/set
import java.io._
import java.util.{Date, Properties}
import org.apache.commons.io.IOUtils
object PropertiesLoadStore {
def main(args: Array[String]) {
val configFile = new File("PropertiesLoadStore.properties")
val config = new Properties
// load
if (configFile.exists) {
var in: InputStream = null
try {
in = new FileInputStream(configFile)
config.loadFromXML(in)
} catch {
case e: IOException => e.printStackTrace
} finally {
IOUtils.closeQuietly(in)
}
}
// get
println(config.getProperty("言語"))
println(config.getProperty("updatedAt"))
// set
config.setProperty("言語", "日本語")
config.setProperty("updatedAt", new Date().toString)
// store
var out: OutputStream = null
try {
out = new FileOutputStream(configFile)
config.storeToXML(out, "Properties test")
} catch {
case e: IOException => e.printStackTrace
} finally {
IOUtils.closeQuietly(out)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment