I/O using Apache POI from an IDE works fine, but when exporting it in a runnable JAR and then have it wrapped in an exe, the output turns out to be question marks only. And since XWPFDocument only writes to an OutputStream, explicitly specifying the encoding is not possible. So, what would be a solution to this? Here's the relevant code:
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
}
thank you in advance!
Okay, solved it! the problem was me encoding a string from UTF-8 to UTF-8 again, which apparently made no sense. I'm leaving this answer since what made troubleshooting this problem kinda tough was the fact that there are 3 components to my program.
String theString = new String(theTextArea.getText().getBytes(), "UTF-8");
I had solved that bug but this constructor looked too beautiful for me to change it back to just:
String theString = theTextArea.getText();
Voila, I ran the program to have it compiled, exported it, did everything normally and the problem is gone. I hope those who have such problem find this answer. And I apologize for my stupidity, XD.