0

我编写了一个 FileMerge 类,我在其中获取一个 rtf 并用 SQL 数据替换某些标签。一切都很好,但是我用一行或多行替换一个标签的一部分,它替换了文件,但是 \n 或 \r\n 在 word 中打开时不会创建新行。

编码:

String otherFamilyString="\n";


    for(int i=0;i<OtherFamily.size();i=i+TotalArguments)
    {
        otherFamilyString +=  "\n"+OtherFamily.get(i+FamilyMbrId) +"|\t"+ OtherFamily.get(i+FamilyMbrName) +"|\t"+ OtherFamily.get(i+FamilyStatus)+"|\t"
        + OtherFamily.get(i+FamilyCoveragetype) +"|  "+ OtherFamily.get(i+FamilyRelationship) +"|" ;
        System.out.print(i+" "+otherFamilyString);


    }
    newtext = newtext.replaceAll("OTHERFAMILY",otherFamilyString);



    FileWriter writer = new FileWriter(outPutDir+memberInfo.get(GroupId).replace(" ", "")+newName.replace("*", "")); 
    writer.write(newtext);//write the new file 
    writer.close();

我也尝试过 System.getProperty("line.separator") 失败。

当我在记事本中打开文件时,我可以看到所有代码都是富文本格式,除了这部分以正确的结构显示。我想我需要一种以富文本格式编写此字符串的方法,以便在单词中显示良好。

谢谢你的帮助,伊丹。

4

2 回答 2

1

以下是一些与 RTF 格式有关的文档:http ://search.cpan.org/~sburke/RTF-Writer/lib/RTF/Cookbook.pod#RTF_Document_Structure

It says to specify a newline using a \line command.

于 2011-08-02T13:54:08.023 回答
0

In RTF, line breaks are not indicated by a new line in the text - instead, you must use the right control sequence to do this. From skimming over the specification, \line looks like a hard line break, and \par like a paragraph break.

于 2011-08-02T13:56:28.207 回答