使用 Apache POI 从可执行文件中输出问号(编码错误?)

output using Apache POI from an executable results in question marks (wrong encoding?)

I/O 使用来自 IDE 的 Apache POI 工作正常,但是当将其导出到可运行的 JAR 中然后将其包装在 exe 中时,输出结果只是问号。由于 XWPFDocument 仅写入 OutputStream,因此无法显式指定编码。那么,解决这个问题的方法是什么? 相关代码如下:

try (var WordOutput = new FileOutputStream(whichFile, true);
                var MSDoc = new XWPFDocument(OPCPackage.open(whichFile));)
        {   //inside try block now
            List<XWPFTable> tables = MSDoc.getTables();
            tables.toArray();
    var ArabicRow = ArabicTable.getRow(0);
                ArabicRow.getCell(1).removeParagraph(0);
                //adding a paragraph with a right alignment:
                XWPFParagraph arabicParagraph = ArabicRow.getCell(1).addParagraph();
                arabicParagraph.setAlignment(ParagraphAlignment.RIGHT);
                
                 CTP ctp = arabicParagraph.getCTP();
                  CTPPr ctppr;
                  if ((ctppr = ctp.getPPr()) == null) ctppr = ctp.addNewPPr();
                  ctppr.addNewBidi().setVal(true);
                
                //a Run is the content of the paragraph, plus other properties.
                XWPFRun arabicSentence = arabicParagraph.createRun();
                
                String theString = "\u202E" + (Arabic text here) + "\u202C";
                 MSDoc.write(WordOutput);
        } catch(Exception e) { 
            //my exception handler
        }   

提前致谢!

好的,解决了! 问题是我再次将字符串从 UTF-8 编码为 UTF-8,这显然没有意义。我要留下这个答案是因为我的程序有 3 个组件,所以解决这个问题有点困难。

  1. Apache POI(我一直怀疑它)。
  2. Java外汇
  3. Java(确切地说是 JVM)。 我从 TextArea 中获取了写入 word 文件的字符串,在另一个 bug 搜索过程中,我将其编码为 UTF-8:
String theString = new String(theTextArea.getText().getBytes(), "UTF-8");

我已经解决了那个错误,但是这个构造函数看起来太漂亮了,我无法将它改回:

String theString = theTextArea.getText();

瞧,我 运行 编译、导出程序,一切正常,问题消失了。我希望那些有这样问题的人找到这个答案。我为我的愚蠢道歉,XD。