Word Files in Java

Hi everybody,
I know this question has probably been asked a zillion and one times before, but I think I might be putting a bit of a new spin on it.
Anyway, I was looking at the Jakarta API's to read and write Microsoft Word Files in Java, and I couldn't make heads or tails of them. Since they have packages you import, though, that means that there must be some Java solution to the problem. So, my question is this--does anyone here know of any Java stream classes, depreciated or otherwise, that can read Microsoft Word's encoding? I've heard rumors that some depreciated classes might be able to do the job; if I'm just completely wrong I'd appreciate it if someone would correct me so I'm not clinging to false hope. Failing an answer to that question, does anyone know if it's possible to get source code of the Jakarta packages?
Thanks,
Jezzica85

Thanks TuringPest,
I feel a bit stupid for saying this, but I can't make any sense of their source code either or tell which files are supposed to be for Microsoft Word; maybe it's just because of how it's written.
What exactly does a proprietary format mean? I think I've heard the term, but I'm not sure.
I'm starting to think my idea of writing some of my own code is too ambitious, but I thought this might be simple. All I want to do is get text out of a Word file, I don't want to open a file to edit it, and I don't care about formatting. Maybe if I understood the file format I could get myself started, I hope I don't sound like a broken record.
Actually, I've written a macro into Microsoft Word that saves as a text file, so I can do it that way, I was just hoping there might be an easier way so I wouldn't need to deal with the extra file--is this probably the best way to go anyway?
Thanks again,
Jezzica85
Message was edited by:
jezzica85

Similar Messages

  • Uplod word file from java

    how we upload word file from java web page?? pls is urgent.

    > i not understand. pls explain?
    Ok. Take a look at the Fundamentals-forum where your post is in. If you look at the 30 most recent threads there are more tthen 10 thread about uploading files. A couple of those have some usefull answers which you probably can use.
    It's always a good habit to search a forum first before you post your question.
    Good luck.

  • How to parse a MS word file from JAVA

    How do i read the contents of MS word file in java? I know that FileInputStream can be used to read the contents in bytes but i need to parse the content of the file also so any pointers on this would be helpful for me.
    I have tried out the API given out by POI by apache but i am not able to figure any thing out of that so it would be very helpful if some posts a sample code for the above problem.

    but i am not able to figure any thing out of thatUse XML, as DrLJ just proposed. But be warned that if you are going to be dealing with Word documents you will have to spend some time learning how they are formatted, even the XML versions. Don't expect to just throw down a FileInputStream and have things happen automagically. It's a complicated format.

  • How to attach a word file in JAVA mail

    I am a JAVA rookie and I have a problem in attaching a word file using javamail. I searched almost all the forum but still couldn't find the solution.
    Sorry for the reposting. But can anybody please help me out? Your any words or links will be highly appreciated!
    Lakobe

    Sorry, this forum is for questions about the javadoc tool.
    There won't likely be JavaMail experts here.
    I'm not sure where else to send you.

  • How to attach a word file in JAVA mail? Please help

    I am a JAVA rookie and I have problem attaching a word file using javamail. I searched almost all the forum but still couldn't find the solution.
    Sorry for the reposting. But can anybody please help me out? Your any words or links will be highly appreciated!
    Lakobe

    If you want to include an attachment with your message, you need to build up the parts, quite literally, because the name of the applicable interface is Part. The content of your Message will consist of multiple parts within a Multipart object. Part one of the message is a BodyPart that contains the message content. Part two of the message is a BodyPart that contains the attachment. The attachment itself is specified as a DataSource. You don't have to actually read the attachment.
    You start in the same way as you do for a message without an attachment. Create the message from the session and initialize the headers:
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO,
    new InternetAddress(to));
    message.setSubject("JDC Attachment");
    However here you need to create the Multipart object:
    Multipart multipart = new MimeMultipart();
    For part one, create a BodyPart and set the text to be a message. Then, add the BodyPart to the Multipart you just created.
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText("Here's the file");
    multipart.addBodyPart(messageBodyPart);
    For part two, you need to create a BodyPart again, but this time you need to create a DataSource for the file.
    messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(filename);
    Use a DataHandler object to attach the data source to the message. Simply create a DataHandler for the source and attach it to the message:
    messageBodyPart.setDataHandler(
    new DataHandler(source));
    Remember to set the filename of the attachment. This permits the recipient to know the name (and type) of the received file.
    messageBodyPart.setFileName(filename);
    Attach part two in the same way as part one:
    multipart.addBodyPart(messageBodyPart);
    And as a final step before sending, attach the Multipart to the Message:
    message.setContent(multipart);

  • Can i create & use ms-word files with java?

    I am making an application in which I need to write some information into a formatted ms word document. I am familiar with writing into a .txt file, but have no idea how to create / or even add info taken from text fields and insert it into an exixting word file. If anyone has any ideas or code frags I would really appreciate the help. Thanks

    Provided that you are on a Windows machine and that Word is installed, you can manipulate an instance of the MSWord ActiveX control to create documents (that's how we do it). See:
    http://danadler.com/jacob/

  • Word file from java

    i need to draw an arrow in word file ( i mean want to generate word file dynamically).
    depending upon particular conditions I want to format the word file
    I'll have to use JNI...
    with VB or C++?

    try this one :-)
    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q196776
    That's all you need, it worked for excel so it will work for word too.

  • Possible to read/ write word files using Java?

    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 :)

    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.
    import java.io.*;
    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){
                   contents.append(line);
                   contents.append(System.getProperty("line.separator"));          
              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();
              z.finalReplace(text);
              input.close();
         catch (FileNotFoundException ex) {
              ex.printStackTrace();
         catch (IOException ex){
              ex.printStackTrace();
         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));
                   sb.append(newSubstring);
                   fromIndex = e + oldSubstring.length();
              sb.append(text.substring(fromIndex));
              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));
                   output.write(endResult);
              finally {
                   if (output != null) output.close();
                 return endResult;

  • How to read word files using java

    Reding text files is prity simple. But when i tried to read msword file I could do it.
    Can any one discuss how to do it
    Thanks

    Sorry this is not a reply but in fact i need the solution for that as i am in an urgency of that can you post that to to me if u have got it, I need it for my project

  • How to read MS Word file

    Hi,
    How can i read MS word file in java ? My problem is that want to read .doc file and convert this .doc file into .txt tile . I was try with Jakarata POI , but i m not found out POI ?
    How to use Jakarata POI for reading .doc file ?
    Thanks in advance
    madhu
    [email protected]

    I believe your looking for the <input type="file" tag to read a file from the user's browser to the servlet. There are examples of this on line. POI is used after the file is read into the servlet to extract its information.

  • How to read the content of ms-word file use pure java???

    how to read the content of ms-word file use pure java???

    hi,
    check this: http://jakarta.apache.org/poi/

  • Opening a word file in MS Office Word software window through Java code

    I want to open a word file in MS Office Word software window through Java code.
    Is it possible ? If possible then please let me now how can I do it.
    Bhoopender

    Thanks for replying.
    I tried the following code -
    public class OpenFileWithItsExt
         public static void main(String[] args) throws java.io.IOException
              Runtime.getRuntime().exec("a.doc");
    and it gets compiled successfully, but on running outputs as -
    Exception in thread "main" java.io.IOException: CreateProcess: a.doc error=193
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Win32Process.java:66)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:566)
    at java.lang.Runtime.exec(Runtime.java:428)
    at java.lang.Runtime.exec(Runtime.java:364)
    at java.lang.Runtime.exec(Runtime.java:326)
    at OpenFileWithItsExt.main(OpenFileWithItsExt.java:5)
    My file is in the pesent working directoty.
    Please solve my problem.
    Thanks

  • Java Swing frame for modification Excel file or Word file with All menu...

    Hello All,
    Can Any one help me for making java Swing frame for modification Excel Data or word file with all Menu.. Plz send me java Code for that.. I am bit new in Swing.
    i am waiting for ur help..
    Thanks
    Samir

    hi pbrockway2 ,
    Can you go through this program Sir, i am trying to call Excel content below of menu. when i will press Edit button then excel content should come below with Cut, copy, paste , Save Button..
    Plz help me sir...
    import javax.swing.*;
    import java.io.*;
    import java.awt.event.*;
    public class TestReader
    private static void createAndShowUI()
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame=new JFrame("Test Reader");
    JButton button=new JButton("Edit");
    button.addActionListener(new ButtonListener());
    frame.getContentPane().add(button);
    frame.setVisible(true);
    frame.pack();
    static class ButtonListener implements ActionListener
    public void actionPerformed(ActionEvent event)
    openTheFile();
    private static void openTheFile()
    try
    String commands[]=new String[3];
    commands[0]="cmd.exe";
    commands[1]="/C";
    commands[2]="INSTALL.LOG"; // here file name is supposed to be in the working dir
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec(commands);
    StreamGobbler errorGobbler=new StreamGobbler(proc.getErrorStream(),"ERROR");
    StreamGobbler outputGobbler=new StreamGobbler(proc.getInputStream(),"OUTPUT");
    errorGobbler.start();
    outputGobbler.start();
    catch (Exception e){}
    public static void main(String args[])
    SwingUtilities.invokeLater(new Runnable()
         public void run()
         createAndShowUI();
    static class StreamGobbler extends Thread
    InputStream is;
    String type,root;
    StreamGobbler(InputStream is,String type)
    this.is=is;
    this.type=type;
    public void run()
    try
    InputStreamReader isr=new InputStreamReader(is);
         BufferedReader breader=new BufferedReader(isr);
         String line=null;
         while ((line=breader.readLine())!=null)
         System.out.println(type+">"+line);
    catch (Exception e)
         System.out.println(e);
    Thanks
    SamiR

  • Merging Word (RTF) files in java

    Hey,
    I have a requirement to merge several word (or rft) files in java. The files are stored as blobs on the database. I had a look at http://poi.apache.org/hwpf/docoverview.html but that project seems to be parked at the moment. Has anybody any ideas?
    Thanks

    I agree its a bad idea but i was asked to look into
    its possibility.
    Previously it wasn't a problem as it was always one
    word file that was required
    for editing through the browser by the user but now
    they want to basically build a 'master doc' based on
    a bunch of business rules i.e. chose a subset of all
    their templates based on business rules at runtime.
    I pitched the idea of generating XSL:FO and adding
    conditionals around the various templates and then
    generating RTF from this. Storing the XSL:FO on the
    db but they didn't like that as they want to be able
    to add and modify new templates and then store these
    directly on the DB?!?!?!The way to address this is to find out what the real concerns are. Almost all stupid requirements are based upon some concern that is the result of a combination of fear and ignorance.
    So I would suggest you find out what the real concern is and address that specifically in your better design.
    Because the reality is that your solution is actually workable. Whereas the one you are being pushed towards will be very difficult and I fear result in an unmaintable mess.

  • How to open an MS-Word-File from a Java-Applikation ?

    Hi,
    i want to open an MS-Word-File from a Java-Applikation.
    Something like this:
    File myFile = new File("myFile.doc");
    myFile.open(); //unfortunately this methode doesn't exist
    Thanks for response

    In my opinion you have to use the Runtime.exec(String) method. I do not know the program name for msword.
    You can open a file in notepad by invoking the method Runtime.getRuntime().exec("notepad c:/xyz/abc.txt");
    Runtime runTime = Runtime.getRuntime();
    runTime.exec("programName" + " " + file);
    Of course the computer on which the program runs must have the application!
    Hope this helps!

Maybe you are looking for

  • Derivation Of partner profit center in COPA (Direct Posting from FI)

    When posting from SD partner profit center is derived and transfered to COPA, so eliminations can take place. When ever we made posting from SD, Partner profit center is coming from derivation rule which is exclusively for sales and maintained in tra

  • Outlook 2013 something went wrong sorry we ran into a problem

    my outlook started hanging and causing problems a few days ago where sent messages were sitting in outbox without sending. and when you closed and reopened outlook the messages has vanished completely without sending. I'm unable to get outlook to ope

  • ADAPTER in the Central Adapter Engine

    Hello I have problem with my Adapter in the Central Adapter Engine. There are to adapter inside, a JMS and A JDBC. This two adpater have in the monitoring status green. But JMS adapter get no message in the system, and by the JDBC adapter the select

  • Mail all email as read

    when configuring my gmail account, iphone downloaded all my existing email from the server. thats understanable since its a pop account, but is there a way for me to mark all messages as already read in the iphone, without doing it one by one ? there

  • Save Project As?

    I only just now realized that the project does not update when it saves until you quit out of Visual Studio. As such I now have 7 backups that are exactly the same, including the main file. I would have lost hours of work if not for finding a copy th