Skip to content

Instantly share code, notes, and snippets.

@akunzai
Last active March 12, 2019 08:46
Show Gist options
  • Select an option

  • Save akunzai/61380a539636400a5bf9323fdecee5cb to your computer and use it in GitHub Desktop.

Select an option

Save akunzai/61380a539636400a5bf9323fdecee5cb to your computer and use it in GitHub Desktop.
Java Properties Converter
if (args.length == 0) {
println("Usage: groovy prop2xml.groovy messages.(properties|xml) [format]")
println("read from STDIN: groovy prop2xml.groovy - [format]")
System.exit(0)
}
def input = args[0] == '-'
? System.in
: new File(args[0]).newInputStream()
def format = args.size() > 1
? args[1]
: args[0].substring(args[0].lastIndexOf(".") + 1)
def props = new Properties()
input.withStream { stream ->
if (format.endsWith("xml")) {
props.loadFromXML(stream)
props.store(System.out, null)
} else {
props.load(stream)
props.storeToXML(System.out, null)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment