AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



java-file-handling: How to display a doc file in a textarea in java?

Please help me to display a MS word file in a textarea using java code.

java x 211
file-handling x 9
Posted On : 2014-07-09 23:38:39.0
profile Garima Gupta - anyforum.in Garima Gupta
596129560202
up-rate
5
down-rate

Answers


Following is the java code to read the doc file and print it on console. and in the same way, if you can print it on console then you can set in a textarea also. When it comes to read Microsoft Office Word document, Java does not have any in build classes to handle this but Apache POI Package developed by Apache Foundation gives you the power of reading Microsoft Word document in Java. More information on the Apache POI package can be found at Apache POI-Click Here

ReadDoc.java:
----------------------------

import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.extractor.*;
import java.io.*;

public class ReadDoc
{
public static void main( String[] args )
{
String filesname = "Hello.doc";
POIFSFileSystem fs = null;
try
{
fs = new POIFSFileSystem(new FileInputStream(filesname;
//Couldn´t close the braces at the end as my site did not allow it to close

HWPFDocument doc = new HWPFDocument(fs);

WordExtractor we = new WordExtractor(doc);

String[] paragraphs = we.getParagraphText();

System.out.println( "Word Document has " + paragraphs.length + " paragraphs" );
for( int i=0; i<paragraphs .length; i++ ) {
paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n","");
System.out.println( "Length:"+paragraphs[ i ].length());
}
}
catch(Exception e) {
e.printStackTrace();
}
}
}




*********** Following is the link of complete application to display doc in a textarea ***********

Source code to display a doc file in a textarea- Click Here

Posted On : 2014-07-10 13:03:51
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188250042
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in