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