code_junkie

How to use Java to edit a template document (form letter) from a file?

Nov 12th, 2011
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. Object[] arguments = {
  2. new Integer(7),
  3. new Date(System.currentTimeMillis()),
  4. "a disturbance in the Force"
  5. };
  6.  
  7. String result = MessageFormat.format(
  8. "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.",
  9. arguments);
  10.  
  11. output: At 12:30 PM on Jul 3, 2053, there was a disturbance
  12. in the Force on planet 7.
  13.  
  14. C:oreyessamplesjavareplace>type Simplistic.java
  15. public class Simplistic{
  16. public static void main( String [] args ) {
  17. String template = "Dear _NAME_HERE_. I'm glad you...";
  18. System.out.println( template.replaceAll("_NAME_HERE_","Oscar Reyes"));
  19. }
  20. }
  21.  
  22. C:oreyessamplesjavareplace>java Simplistic
  23. Dear Oscar Reyes. I'm glad you...
Add Comment
Please, Sign In to add comment