Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Mar 12, 2024 8:18 am

Hi,
We use SpireDoc for Java (12.3.1)
Code: Select all
        Document document = new Document();
        document.loadFromFile(file.getRef().path().toString(), FileFormat.Auto);


And getting error:
Code: Select all
Caused by: java.lang.IllegalArgumentException: Cannot detect current file type
   at com.spire.doc.Document.spr???�(Unknown Source)
   at com.spire.doc.Document.spr???�(Unknown Source)
   at com.spire.doc.Document.spr???�(Unknown Source)
   at com.spire.doc.Document.loadFromFile(Unknown Source)
   at controllers.test.SpireDocConversion.convert(SpireDocConversion.java:28)


Thanks,
Andrei Chorin

andrei.chorin
 
Posts: 48
Joined: Sun Jan 08, 2023 2:36 pm

Wed Mar 13, 2024 2:03 am

Hello,

Thanks for your inquiry.
Sorry, after testing, I couldn't reproduce the issue you mentioned. Here's the code I used:
Code: Select all
Document document = new Document();
document.loadFromFile("D:appendency\\appendency.docx",FileFormat.Auto);

Kindly note that the first parameter of the "loadFromFile (String fileName, FileFormat fileFormat)" method is the path to the input file, for example: D: xxx\xx\appendency.docx. If this parameter is incorrect, it may cause problems you may encounter. Therefore, please check if the "file. getRef(). path(). toString()" in your code is correct. In addition, you can also process your file into a file stream and use the "loadFromStream (InputStream, FileFormat fileFormat) " method to load it. Please try again following the above suggestion. If it still doesn't work, could you provide a simplified and runnable project with us? We'll further investigate. Thank you in advance.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 203
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.Doc