POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry directory = fs.getRoot();
directory.createDocument("WordDocument", new ByteArrayInputStream(content.getBytes()));
FileOutputStream out = new FileOutputStream(FileName);
fs.writeFilesystem(out);
out.close();
i'm creating (.doc) file using the above code. File created using the above code is opening in MicrosoftWord. But when i'm trying to open the same file in Jtextarea using the below code
WordExtractor extractor = null;
tabcount = e.jTabbedPane1.getSelectedIndex();
try {
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
HWPFDocument document = new HWPFDocument(fis);
extractor = new WordExtractor(document);
String fileData = extractor.getText();
if (fileData != null) {
e.textAreas[tabcount].append(fileData);
}
but the file created using MicrosoftWord opened by above code.
Lester Burnham
Rancher
Joined: Oct 14, 2008
Posts: 1337
posted
0
The error is not occurring in the POI code, it's in the Swing code, so it's not surprising that there are no problems opening the file in Word. You didn't say in which line the exception happens, but it's probably in "e.textAreas[tabcount]", since that's the only array being used. Apparently, the textAreas array does not have 5 elements, so trying to access element #4 won't work. (Remember that arrays are 0-based in Java, so at index 4 is the 5th element).
Vicky Thakor
Greenhorn
Joined: Sep 04, 2010
Posts: 19
posted
0
Lester Burnham wrote:The error is not occurring in the POI code, it's in the Swing code, so it's not surprising that there are no problems opening the file in Word. You didn't say in which line the exception happens, but it's probably in "e.textAreas[tabcount]", since that's the only array being used. Apparently, the textAreas array does not have 5 elements, so trying to access element #4 won't work. (Remember that arrays are 0-based in Java, so at index 4 is the 5th element).
- I know that but as i said...The "doc" file created using POI library is not get open in the jTextarea but other "doc" file created using MicrosoftWord is opening in jTextarea
Lester Burnham
Rancher
Joined: Oct 14, 2008
Posts: 1337
posted
0
I think you missed what I was trying to convey. The problem has nothing to do with handling a Word document, and also nothing to do with the POI library.
The problem is that the code is using an array index that is invalid. You still haven't told us in which line of code the exception happens, so I'm assuming it's in "e.textAreas[tabcount]". Apparently tabcount has a value of 4, while textAreas has a size of less than 5. That's where you should begin investigating.
On the other hand, if the exception happens in some other line of code, then it's high time you told us which line that is (and also posted the full stack trace of the exception).
Vicky Thakor
Greenhorn
Joined: Sep 04, 2010
Posts: 19
posted
0
Lester Burnham wrote:I think you missed what I was trying to convey. The problem has nothing to do with handling a Word document, and also nothing to do with the POI library.
The problem is that the code is using an array index that is invalid. You still haven't told us in which line of code the exception happens, so I'm assuming it's in "e.textAreas[tabcount]". Apparently tabcount has a value of 4, while textAreas has a size of less than 5. That's where you should begin investigating.
On the other hand, if the exception happens in some other line of code, then it's high time you told us which line that is (and also posted the full stack trace of the exception).
The above error i'm getting....
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.