Java code
package com.sunyard.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class OperatorRTF {
/**
* 字符串转换为rtf编码
*
* @param content
* @return
*/
public String strToRtf(String content) {
try {
System.out.println(content);
content=new String(content.getBytes(),"GB2312");
System.out.println(content);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
char[] digital = "0123456789ABCDEF".toCharArray();
StringBuffer sb = new StringBuffer("");
byte[] bs = null;
bs = content.getBytes();
int bit;
for (int i = 0; i < bs.length; i++) {
bit = (bs[i] & 0x0f0) >> 4;
sb.append("\\'");
sb.append(digital[bit]);
bit = bs[i] & 0x0f;
sb.append(digital[bit]);
}
return sb.toString();
}
/**
* 替换文档的可变部分
*
* @param content
* @param replacecontent
* @param flag
* @return
*/
public String replaceRTF(String content, String replacecontent, int flag) {
String rc = strToRtf(replacecontent);
String target = "";