Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I easily (in java) generate file names from a mask string?

Tags:

java

filenames

I want to generate file names from a mask in Java.

Something like 'Data-12-08-29-xxx.xml' from a mask like 'Data-${YY}-${MM}-${DD}-${var1}.xml'. I dont want to generate random file names, instead the file names would built according to a pattern provided at runtime.

I can imagine just what I need to create a nice, generic class that will handle this for all manner of cases, but I dont want to reinvent the wheel, if something exists out there that I can re-purpose and perhaps extend.

Any suggestions?

like image 649
cmdematos Avatar asked Aug 29 '12 14:08

cmdematos


1 Answers

the Formatter class (the functionality behind String.format()) has a very powerful formatting syntax (much more powerful than MessageFormat). It can handle variable substitution as well as date formatting.

like image 160
jtahlborn Avatar answered Sep 20 '22 14:09

jtahlborn