How to edit template documents (form letters) from files using Java?

This is my first time playing Java. I need to be able to replace some words in the template Sample template –

"Dear put_their_name_here,

I'm contacting you bla bla bla

to greet,

PUT_ COMPANY_ NAME_ HERE”

What is the easiest way (preferably using the standard library) to make a copy of this template file, add the correct words in the correct location, and then save it to the file system? I have to do a lot of such simple templates, so an easy to copy way will be good

I also use rhino to access Java through JavaScript. I'm not sure if it's different

to greet,

Chris

Solution

You are looking for Java text. messageformat:

Here are some usage examples (from Javadoc):

Object[] arguments = {
     new Integer(7),new Date(System.currentTimeMillis()),"a disturbance in the Force"
 };

 String result = messageformat.format(
     "At {1,time} on {1,date},there was {2} on planet {0,number,integer}.",arguments);

 output: At 12:30 PM on Jul 3,2053,there was a disturbance
           in the Force on planet 7.
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>