We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Strange FileCorruptedException

Hi, I’m getting a strangeFileCorruptedException. I’m trying to open an html file (eg attached hello.html.zip) and I’m just calling the Document constructor with the filepath string. The strange part is if I run the code in a unit test it works, but if I run the same code on the same input file in the production environment (j2ee app, jetty server, java 6) it throws the exception. The libraries are the same, the input file is the same (path hardcoded, etc), everything else looks same to me. If I change the input to be a word doc it works, so I don’t think it’s a file permission issue, etc, only html.

Here is the stack trace:

com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.

at com.aspose.words.Document.a(Document.java:1382)

at com.aspose.words.Document.b(Document.java:1369)

at com.aspose.words.Document.a(Document.java:1257)

at com.aspose.words.Document.(Document.java:143)

at com.aspose.words.Document.(Document.java:117)

Using: Aspose.Words for Java 4.0.3, java 1.6.0_22, mac os x 10.6

I know it’s a strange issue, and possibly something on my end, but if the stack trace can give a clue as to what the issue might be, I’d be very grateful!



Hi Jacob,

Thanks for your inquiry.

There are a couple of cases of issues with loading HTML using Java that work on one machine but not another. These often result in an UnsupportedCharSet exception which is not the case here but the underlying issue might be the same. Please try loading the HTML using the code below and see if that helps.

InputStream is = new ByteArrayInputStream(html.getBytes());
Document doc = new Document(is,"",LoadFormat.HTML,"");
doc.save("document out.doc", SaveFormat.DOC);


Thanks Adam, this works! Strangely enough, this also works:

Document doc = new Document(htmlFile.getAbsolutePath(), LoadFormat.HTML, “”);

It might be that the issue is in the format auto-detect, though I’m not sure why it would work in a unit test and not in the j2ee server.

Anyways, thanks for your help!


Hi Jacob,

It's great it's working correctly. Yes, it is probably something to do with the auto detection going wrong but we haven't ever been able to reproduce it on our side in order to test.

Hopefully this issue will dissapear in the next version of Aspose.Words for Java which will be the first version which is auto ported from .NET

If you have any further queries, please feel free to ask.