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]

In august 24,2010, I bought a macbook pro 13-inch from apple on-line store. But today, my power regulator of magsafe was broken. I don't know what's wrong with it. I use my friend's magsafe, and his magsafe is good. So I want to change another. How c [More]
Hello, I have made a search page. And from the search page I select an item and then update it. After updating I come back to the search page. When I again try to search I get this error (JBO-35007) on the page. No error is displayed in the console ( [More]
Hi, I was wondering if someone could assist me.  In PSE 9, I opened a photo>selected it>created a new layer and applied an inner shadow without a problem.  However, when I selected the TEXT tool and wrote some text in a new layer on top of the photo [More]
Hi, I am using Jdev My requirement was to called some action using the keyboard key. I tried with Access key first but its behaving differently in different browser. Crome: allowing action on access key press. IE : setting the focus on com [More]
I need help with an applescript that can look at a pdf, determine the page count in file and then add that value to the end of the file name in front of the .pdf ex. original name "map with pages4c.pdf" renamed "map with pages4c_48.pdf" [More]
Hi all, I locked period in Tcode OKP1 for all transaction However, transaction in 9KE0 is not locked yet I don't know why. Can anybody help me? Thanks and regardsHi, thathere is no possibility to lock periods / posting transactions in PCA (including [More]
Hi everyone. I need to make the Shipping Condition field required in the transsaction VT01N Create Shipment. I don't know how to do this, can somebody help me with this issue??? Thanks for your help!Hi Chemo, As far i undestand, you want to calculate [More]
Hi I have a data file as below with column names Emp ID,Emp name ,Dept id,Dept name Emp ID,Emp name ,Dept id,Dept name 10,name 1,100,Dept 1 11,name 2,101,Dept 2 12,name 3,102,Dept 3 I want to load this into two tables employee and depatment as below [More]
Dear All,          I was trying to load a Hierarchy from R/3 to BI 7.0 . I get an error "EDI: Partner profile not available". When I go to R/3 TC we05 I get under Inbound Docs> RSRQST > status 64 for Idocs specifying this error. I donot fi [More]
I have multiple ibook g3's and all with the same problem. They wont turn on, its not dc-board, not power adapter, it is something to do with the logic board but i'm trying to narrow it down more. When i hit the power button i hear a very,very faint h [More]