I am new to Java and want to add data to an already existing .docx file and so far i've been unsucessful. I've been looking for an answer to this for 3 days now and i decided to come to stackoverflow and ask how i could add text to an existing file using apache poi.
My program is supposed to generate a bunch of random data and store it in a file. Before Apache, i was using .write() to log my data and it was working well but the file didnt have formatting which was fine in the moment but now i need formatting to be able to get a good look at the thousands of data entries.
Here is the code i was using to log the data before:
FileWriter fwriteFinal = new FileWriter("obf_reg.docx", true);
fwriteFinal.write(lbrk);
fwriteFinal.write("\n");
fwriteFinal.write("Your Engine is called: " + engine_Name);
fwriteFinal.write("\n");
fwriteFinal.write("Your Engine Cycle is: " + nuclear_Cycle_Chosen + " " + engine_Cycle_Chosen);
fwriteFinal.write("\n");
fwriteFinal.write("Your Propellant is: " + propellant_List_Chosen);
fwriteFinal.write("\n");
fwriteFinal.write("Your Reactor's Fission Fuel is: " + reactor_Fuel_Chosen);
fwriteFinal.write("\n");
fwriteFinal.write("Your engine's nozzle type should be : " + nozzle_Type_List_Chosen);
fwriteFinal.write("\n");
fwriteFinal.write("Tank repressurisation would be done " + tank_Repressurisation_Chosen);
fwriteFinal.write("\n");
fwriteFinal.close();
and this is what im trying to use:
XWPFDocument docx = new XWPFDocument();
XWPFParagraph par = docx.createParagraph();
XWPFRun run = par.createRun();
run.setText(lbrk + "\n" + "Your Engine is called: " + engine_Name + "\n" +
"\n" + "Your Engine Cycle is: " + nuclear_Cycle_Chosen + " " + engine_Cycle_Chosen +
"\n" + "Your Propellant is: " + propellant_List_Chosen +
"\n" + "Your Reactor's Fission Fuel is: " + reactor_Fuel_Chosen +
"\n" + "Your engine's nozzle type should be : " + nozzle_Type_List_Chosen +
"\n" + "Tank repressurisation would be done " + tank_Repressurisation_Chosen);
FileOutputStream out = new FileOutputStream("C:\\Users\\sfsga\\OneDrive\\Desktop\\obf_reg.docx");
docx.write(out);
out.close();
its prolly a dumb mistake but im still gonna ask.