• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.io.FileNotFoundException

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone,
i made an application to retrieve image from a word document and to save it in a local directory but i am getting some exception.
the code is--->



and the exception i am getting when i run this code is---->


java.io.FileNotFoundException: D:\Hello.doc (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at org.cloud.example.ReadDocFileFromJava.readMyDocume nt(ReadDocFileFromJava.java:31)
at org.cloud.example.ReadDocFileFromJava.main(ReadDoc FileFromJava.java:24)


however the Hello.doc file exists in my D drive.so friends please help me what is the problem.
Thanks in advance.
 
gopal g gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i found the solution the file name should be Hello.doc.docx and i was using only Hello.doc

but i got another exception i.e.

org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. POI only supports OLE2 Office documents
at org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java:108)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:151)
at org.cloud.example.ReadDocFileFromJava.readMyDocument(ReadDocFileFromJava.java:31)
at org.cloud.example.ReadDocFileFromJava.main(ReadDocFileFromJava.java:24)

please help me.
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a file called "Hello.doc.docx"? That's very confusing, wouldn't you think? Is it a DOC or a DOCX file? If it's DOCX, then you need to use the classes in the org.apache.poi.xwpf package to handle them. The org.apache.poi.hwpf package handles DOC files only.
 
gopal g gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
the file name is Hello.doc and its extension is docx.
 
gopal g gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello tim
its a docx file.i am new to java so please can you help me what modification should i made in my example.
thanks in advance.
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

the file name is Hello.doc and its extension is docx.


So you're saying that you don't think that's confusing? What happens if you need to pass that file on to other people - do you think they might find it confusing? Or that it might be better to avoid any cause for confusion in the first place?

its a docx file.i am new to java so please can you help me what modification should i made in my example.


I already told you which classes to use - the HWPF and XWPF packages are structured very similarly; you should have little trouble adapting your code if you study the javadocs.
 
gopal g gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am unable to modify this code for docx file.so anyone can send me a sample code to extract image from docx file....
thanks in advance.
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i am unable to modify this code for docx file.


Why? What have you tried, and how does it not work? Post the code you have now.
 
gopal g gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my code

 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the code do, and how does that differ from what you expected it to do? (Note that you didn't post the import statements, just in case you were expecting anyone to compile it on their own.)
 
gopal g gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to extract image and text from a doc file. the code which i am trying works well.but now i want to extract image and text from docx file then this code throws an exception.
the code is-->



and the exception is-->


org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
at org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java:111)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:151)
at org.apache.poi.hwpf.HWPFDocument.verifyAndBuildPOIFS(HWPFDocument.java:119)
at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:132)
at com.doylecentral.word.ReadDocFileFromJava.readMyDocument(ReadDocFileFromJava.java:33)
at com.doylecentral.word.ReadDocFileFromJava.main(ReadDocFileFromJava.java:24)

so please send me a sample code for docx file.since i am new to java so it is more difficult to make changes.
thanks in advance.
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then this is a good opportunity to learn, which I assume you want to do. If not, then this is probably not the right place to ask for help.

Instead of the classes in the org.apache.poi.hwpf package you need to use classes in the org.apache.poi.xwpf package. The classes are named very similarly, often just "XWPF" instead of "HWPF". If you spend some time with the javadocs (which you should) then things should become much clearer.
 
gopal g gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you tim.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic