Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Content in text file to MS Word file help!

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Content in text file to MS Word file help!

    Hey,

    I have tried (and sadly failed) to print out the content from a text file into a new Microsoft Word document.
    Below is the code from my attempt. Also, I can't download any other additional libraries other than the usual ones.

    Microsoft Word won't open up the file as it can't read the contents and says it's corrupt.

     
        public static void exportMS() throws IOException {
            File exp = new File("Menu.docx");
            File cou = new File("Courses.txt");
            PrintWriter pw = new PrintWriter(new FileWriter(exp));
            BufferedReader brC = new BufferedReader(new FileReader(cou));
            while (brC.readLine() != null) {
                pw.println(brC.readLine());
            }
            brC.close();
            pw.close();
        }

    Also, is it possible to append other text files to the same MS Word document?

    Thank you!
    Last edited by ComputerSaysNo; October 26th, 2011 at 04:18 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,302
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Content in text file to MS Word file help!

    Word documents are not just text, they are a particular file format containing all sorts of other important information such as formatting. You will need a 3rd party library - such as Apache POI - to get the actual text of the document, append, and rewrite the file.

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    50
    My Mood
    Fine
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Content in text file to MS Word file help!

    I have only one question here Why can't you download/use other libraries?

    application context
    Last edited by daniel.j2ee; December 13th, 2011 at 04:02 PM.

  4. #4
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Content in text file to MS Word file help!

    I can't download libraries, because the guidelines for my dossier say I can't.

Similar Threads

  1. Reading a text file word by word
    By dylanka in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 21st, 2011, 02:06 PM
  2. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM
  3. Read a text file and parse the contents of file
    By HelloAll in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 3rd, 2011, 04:47 AM
  4. reading content of the text file, splitting it into strings
    By Dodo in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: January 6th, 2011, 06:57 PM
  5. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM

Tags for this Thread