how to read text file using JAVA...??


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: how to read text file using JAVA...??

Hybrid View

  1. #1
    Billy Guest

    how to read text file using JAVA...??


    Hi all,
    Can anyone tell me how to read a test or ms word file using java.

    Actually i want to write a java program that reads a file and generates a
    summary of that file.

    Can it be done using java beans?

    please help me out, im a student and i have a give an exam for this.

    thanx,
    Billy


  2. #2
    Kyle Gabhart Guest

    Re: how to read text file using JAVA...??


    "Billy" <bsharma@maxindia.com> wrote:
    >
    >Hi all,
    > Can anyone tell me how to read a test or ms word file using java.
    >
    >Actually i want to write a java program that reads a file and generates

    a
    >summary of that file.
    >
    >Can it be done using java beans?
    >
    >please help me out, im a student and i have a give an exam for this.
    >
    >thanx,
    >Billy
    >


    Billy,

    There is not a way, that I am aware of, to read an MS Word document in Java.
    MS Word is encoded in a proprietary format that Java cannot easily navigate.
    Reading a text file, on the other hand, can be handled in Java. Want you
    want are the classes made available in the java.io package. You will want
    to open a stream to the document, read the contents (or a portion of them)
    into your program, and then perform whatever processing your program requires.
    I have provided three links that I think you will find helpful:

    http://java.sun.com/docs/books/tutor.../io/index.html

    http://www.ifi.unibas.ch/generate.do...urse/chapter11

    http://java.sun.com/j2se/1.3/docs/ap...e-summary.html

    If you have any other questions, feel free to post another question.

    Happy Coding!

    Cordially,

    Kyle Gabhart
    DevX Java Pro



  3. #3
    Kingshuk Guest

    Re: how to read text file using JAVA...??



    >Can anyone tell me how to read a test or ms word file using java.

    There are no java classes in jdk that lets you read files stored in MS word
    document format. MS Word document format is proprietary and I do not know
    whether the specification of how the document is stored is available.


    >Actually i want to write a java program that reads a file and generates

    a
    >summary of that file.

    As the subject of your posting suggests , if you want to read a plane text
    file you can do it in several ways. Here is a sample , which read each line
    of a text file and prints it out in the standard output.



    String file = "myFile" //assign the filename you want tor read.

    //Open a file reader first. It represents a stream to the file.
    java.io.FileReader fr = new FileReader( myFile ) ;

    //BufferedReader provides a convenient method to read lines from a file one
    at a time. So wrap the filereader created into a BufferedReader.
    java.io.BufferedReader reader = new BufferedReader( fr ) ;
    String line = null ;
    //Now read the file one at a time until you get a null indicating the end
    of file.
    while( ( line = reader.readLine() ) != null )
    {
    System.out.println( line ) ;
    }

    Good luck.

    Kingshuk



  4. #4
    Steve Franklin Guest

    Re: how to read text file using JAVA...??


    "Billy" <bsharma@maxindia.com> wrote:
    > Can anyone tell me how to read a test or ms word file using java.


    I think your best bet would be to convert the word docs
    to RTF and from RTF to XML. Or, you could save from the
    word doc to HTML and use an XML based parser (although
    you will run into some non-compliant sections of the
    generated HTML doc I believe).

    As for generating a coherent summary of the document -
    that is not a trivial problem. You can find a number of
    academic papers on condensing and summarizing text.

    Steve


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center