Hi all,

I'm trying to implement an export functionality to a webapp I've developed. The whole workflow is there's an Elasticsearch query, the results are stored in Arraylist of Article classes, which just contains strings.

Now, within this article class, there's a 'Text' field that has a large text body with line breaks in the middle of it.

When I do a System.out.println(Article.getText()); , I get the properly spaced output in console. However, when I do the export to the .doc file, the linefeeds are replaced with unknown characters ("?"). See attached image.

HWPF Doc File - Handling existing string line break?-30kafl4.png

Here's my code to write the export at this point:

Java Code:
public boolean writeWord(List<Article> Articles, String dir) throws IOException {  
    Hashtable <String, String> langs = getLangName ();  

    new File(dir).mkdir();  

    for (Article A : Articles) {  

        A = nullCheck(A);  


        HWPFDocument doc = new HWPFDocument(new FileInputStream("template.dot"));   

        Range range = doc.getRange();   
        CharacterRun run = range.insertAfter("Text: " + A.getText());   

        OutputStream out = new FileOutputStream(dir + "/" + A.getArticleId() + ".doc");  




    return true;  
Is there a way to determine what that character is that is giving me the ?'s in Word and replace it with System.getProperty("line.separator") ? I just don't know how to go about finding what that character would be in Java.

Thanks in advance!