Results 1 to 3 of 3
  1. #1
    gopal026 is offline Member
    Join Date
    Dec 2011
    Posts
    5
    Rep Power
    0

    Default java.io.FileNotFoundException

    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--->


    public class ReadDocFileFromJava {
    public static void main(String[] args) {
    /** This is the document that you want to read using Java. **/
    String fileName = "D:\\Hello.doc";

    /** Method call to read the document (demonstrate some useage of POI) **/
    readMyDocument(fileName);

    }

    public static void readMyDocument(String fileName) {
    POIFSFileSystem fs = null;
    try {
    fs = new POIFSFileSystem(new FileInputStream(fileName));
    HWPFDocument doc = new HWPFDocument(fs);

    /** Read the content **/
    readParagraphs(doc);

    readImages(doc);

    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    public static void readParagraphs(HWPFDocument doc) throws Exception {
    WordExtractor we = new WordExtractor(doc);

    /** Get the total number of paragraphs **/
    String[] paragraphs = we.getParagraphText();
    System.out.println("Total Paragraphs: " + paragraphs.length);

    for (int i = 0; i < paragraphs.length; i++) {

    System.out.println("Length of paragraph " + (i + 1) + ": "
    + paragraphs[i].length());
    System.out.println(paragraphs[i].toString());

    }

    }

    public static void readImages(HWPFDocument doc) throws Exception {
    PicturesTable picA = doc.getPicturesTable();
    List<Picture> picturesA = picA.getAllPictures();
    for (Picture picture : picturesA) {
    byte[] array = picture.getContent();
    InputStream in = new ByteArrayInputStream(array);
    BufferedImage bImageFromConvert = ImageIO.read(in);

    ImageIO.write(bImageFromConvert, "png", new File(
    "d:\\mypic_new.png"));
    }
    System.out.println(picturesA.size());

    }

    }




    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.

  2. #2
    gopal026 is offline Member
    Join Date
    Dec 2011
    Posts
    5
    Rep Power
    0

    Default Re: java.io.FileNotFoundException

    i solve this problem since the filename should be Hello.doc.docx.

    but now i am getting another ecxeption i.e.

    org.apache.poi.poifs.filesystem.OfficeXmlFileExcep tion: The supplied data appears to be in the Office 2007+ XML. POI only supports OLE2 Office documents
    at org.apache.poi.poifs.storage.HeaderBlockReader.<in it>(HeaderBlockReader.java:108)
    at org.apache.poi.poifs.filesystem.POIFSFileSystem.<i nit>(POIFSFileSystem.java:151)
    at org.cloud.example.ReadDocFileFromJava.readMyDocume nt(ReadDocFileFromJava.java:31)
    at org.cloud.example.ReadDocFileFromJava.main(ReadDoc FileFromJava.java:24)

    so please help me.......

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: java.io.FileNotFoundException

    Get a newer version of POI, or have it read a .doc instead of a docx.

Similar Threads

  1. java.io.FileNotFoundException
    By Naani in forum New To Java
    Replies: 4
    Last Post: 08-18-2011, 02:06 PM
  2. java.io.FileNotFoundException: \temp\env.out
    By JJones in forum New To Java
    Replies: 3
    Last Post: 05-19-2011, 11:07 PM
  3. Java.util.zip FileNotFoundException
    By deredowl in forum Advanced Java
    Replies: 4
    Last Post: 05-18-2011, 09:37 AM
  4. Replies: 1
    Last Post: 04-14-2011, 05:04 AM
  5. java.io.FileNotFoundException
    By thevoice in forum New To Java
    Replies: 5
    Last Post: 06-13-2008, 08:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •