Amicuk Programming Answers

Possible to read/ write word files using Java?

-0001-11-30   Views:0


I'm planning to write a Java application that can read an MS word document, extract something (including mathematics equations created with the equation editor) from the document and write it to another word document. Is it possible to do this? Can a

I'm planning to write a Java application that can read an MS word document, extract something (including mathematics equations created with the equation editor) from the document and write it to another word document.
Is it possible to do this?
Can anyone give me some idea?
Any idea is much appreciated :)

The replay answer
I think I may have misunderstood your question, but in case I didn't and you find this helpful, following is the code to read a word doc, replace certain strings, then write it out as a new doc.
public class Copy {
     public static String endResult;
     public static void main(String[] args) {
          String oldAuthor = "Samuel Foote";
          String newAuthor = "New Author";
          String oldDate = "1720-1777";
          String newDate = "1975 -- ";
      try {
          File inputFile = new File("C:\\document.doc");
          BufferedReader input = null;
          input = new BufferedReader(new FileReader(inputFile));
          StringBuffer contents = new StringBuffer();
          String line = null;
          while ((line = input.readLine()) != null){
          String text = contents.toString();
//     Replace the author and the dates
          Copy y = new Copy();
          y.replace(text, oldAuthor, newAuthor);
          text = endResult;
          y.replace(text, oldDate, newDate);
//     Copy the new, improved text to another file     //
          Copy z = new Copy();
     catch (FileNotFoundException ex) {
     catch (IOException ex){
     String replace(String text, String oldSubstring, String newSubstring) {
//          Search the text for a string, then replace it //
          int fromIndex = 0;
          int e = 0;
          StringBuffer sb = new StringBuffer();
          while ((e = text.indexOf(oldSubstring, fromIndex)) >= 0) {
               sb.append(text.substring(fromIndex, e));
               fromIndex = e + oldSubstring.length();
          endResult = sb.toString();
          System.out.println("final string = " + sb);
          return sb.toString();
     String finalReplace (String args) throws IOException {
//          Move the altered text to a new file  //
          File outputFile = new File("C:\\copied document.doc");
          FileWriter out = new FileWriter(outputFile);
          Writer output = null;
          try {
               output = new BufferedWriter(new FileWriter(outputFile));
          finally {
               if (output != null) output.close();
             return endResult;

Go to See the other 13 answers

Creation of .RTF file in java

Category:DefaultRelease time:2015-10-11Views:130

Hi, I want to create/edit .RTF file through java application. In my RTF file, I should be able to edit data(formatting), inserting tables. This is already done. Now I want to create chart (like pie-chart) using java. I searched the net for the last c[More]

Generation of XML file from Java objects using castor

Category:DefaultRelease time:2015-10-11Views:130

I have the following java file( public class Customer      private String ID;      private FirstName firstName;      private MiddleName middleName;      private LastName lastName;      private ArrayList address;      public ArrayList g[More]

Generation of xml file from java code

Category:DefaultRelease time:2015-10-11Views:130

hi, I want to manipulate data in a xml file with java code.I have read data from xml file and also changed it. But i am unable to covert it again in xml file from java code. Can you please tell me how i can do this?Let me know which parser are you us[More]

Error reading zip file in Java 6

Category:DefaultRelease time:2015-10-11Views:130

We have a bespoke installer program that fails, intermittently, in Java 6 on Windows. After installing some files, it then fails with a stack trace like this: error reading zip file      at[More]

How to read Excel file in java

Category:DefaultRelease time:2015-10-11Views:130

Respected sir/madam I want to read the values from Excel file in Java program. How can I do that. When I searched over the net I came to know that you can treat Excel file as a Database and write the code as u write for making DB connections . I did[More]

Executing batch file from Java stored procedure hang

Category:DefaultRelease time:2015-10-11Views:130

Dears, I'm using the following code to execute batch file from Java Stored procedure, which is working fine from Java IDE JDeveloper public static String runFile(String drive) String result = ""; String content = "echo off\n"[More]

JNI Invocation: open file in Java, write file in CPP

Category:DefaultRelease time:2015-10-11Views:130

Hello, Warning: I am a dunce, bad CPP code ahead! Using JNI invocation, I am trying to read a binary file in Java and write it in CPP. Everything compiles and runs without error, but the input and output jpg files are of course different. TIA to any[More]

How to read pdf files using package classes

Category:DefaultRelease time:2015-10-11Views:130

Dear All, I have a certain requirement that i should read and write PDF files at runtime. With normal java file IO reading is not working. Can any one suggest me how to proceed probably with sample code block Thanks in advance.hi I also have the pbm.[More]

Create crystal report file using JAVA

Category:DefaultRelease time:2015-10-11Views:130

Can someone tell me how to a Create crystal report file using JAVA Programming I want a very simple examplePlease help me. It's urgent.[] Be back in an hour or two...Read other 2 answers[More]

How to create and edit a .ini file using java

Category:DefaultRelease time:2015-10-11Views:130

Hi All... Pls help me in creating and editing an .ini file using java... thanks in advance Regards, sathyaLet's assume the ini file is a mapping type storage (key=value) so lets use Properties object. (works with java 1.4 & up) import; i[More]

How to compare and edit Resource bundle file using java programe

Category:DefaultRelease time:2015-10-11Views:130

Hi All I have two resource bundle with key, value and some comments. I need to write a java code to compare both of the values of the keys and if the values are different then i want to replace the second value with the first value. Its a programe wh[More]

can 2 iphones on the same itunes account to read each other's messages somehow?Yes, if both users are using the same apple id for imessage, you will see each other's message.  So use different apple id.Read other 2 answers [More]
How to set Internet limits to particular user by gpo ? Thanks & Regards, Amol . Amol DhaygudeHi, >>How to set Internet limits to particular user by gpo ? What Internet limits do you want to set for specific users? Group Policy user settings can [More]
Does anyone know if there is a way to share files between Mavericks and Mac OS 9.1 operating system? When I try to connect from my iMac I get a window that says "The version of the server you are trying to connect to is not supported." Is there [More]
Hello all, my name is Merlin and of course... Im new to this! LOL Ive been teaching myself Obj-C and Cocoa for the better part of 5 months now, and I have to say... I found my path. I absolutely love it and cant wait till I feel more comfortable with [More]
Hi We settlement rule for internal order 2500007 was erroneously set to settle costs to asset 11 (company 123). That asset is already part of a different internal order. Costs from internal order ***0007 were settled to that asset in prior periods(fr [More]
im not the administrator of this macbook how can i restore to a factory settings.?To the best of my knowledge Administartor Privilages are needed to Perform what you ask...Read other 2 answers [More]
Hi all, I keep getting this message RCVR_DETERMINATION">NO_RECEIVER_CASE_BE. And I can't figure out why. This is what i created : 1. IMported my object from R3. 2. Created all the mapping for Request, response & fault. 3. Created an Outbound s [More]
I'm trying to get my video files to stream from my local version of flash media server to my instance of a flex application. I'm able to connect to the server and I'm receiving the NetConnection.Connect.Success code from the server. When I debug the [More]
Hi ExpertALL, I need support, check the source and target structures. Source structure below: Target structure: As you can see the structure "item" it´s unbound, means repeat many times, inside <item> there is a tag <TYPE> that´s coi [More]
I usue CMD-delete to trash files all the time and have a multi-button mouse programmed to do this with a single button. If I change the file extension suffix on a file (say .txt to .m2t), the CMD-delete capabilty of my computer goes away until I log [More]