Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Can't Find File Apache Poi

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can't Find File Apache Poi

    I'm trying to read a .xlsx file using Apache Poi on Eclipse and store the data into an ArrayList.

    My code :

     
    import org.apache.poi.ss.usermodel.*;
    import java.io.*;
    import java.util.*;
     
    public class parseReadFiles 
    {
        public static void main(String[] args)
        {
            try
            {
                ArrayList<String> firstList=new ArrayList<>();
                //ArrayList<String> secondList=new ArrayList<>();
                //ArrayList<String> thirdList=new ArrayList<>();
     
                Workbook wb = WorkbookFactory.create(new FileInputStream("Users/Divjot/Desktop/first.xlsx"));
                Sheet sheet = wb.getSheetAt(0); ...
            }
            catch(FileNotFoundException e)
            {
                e.printStackTrace();
            }
            catch(Exception e)
            {
            }
        }
    }


    I keep getting a FileNotFoundException: Users/Divjot/Desktop/first.xlsx (No such file or directory). I've tried different combinations of file names and paths but can't get the program to find it. Should the file be stored in a special place or should the class path be different?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Can't Find File Apache Poi

    The code is looking for a file contained within the Users folder of the root of your project. I presume your file is elsewhere, for instance on the C drive, in which case you should specify the absolute path to the file (eg C:/Users)

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can't Find File Apache Poi

    I'm on a Mac and I tried to find the absolute path but I couldn't. If I click command-I on the file name, it says that it's located under Users/divjot/Desktop/first.xlsx (I tried changing Divjot to lowercase but that didn't work). How can I find the absolute path and is it possible for me to store this somewhere in Eclipse so I don't need the absolute path?

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Can't Find File Apache Poi

    I don't have it in front of me, but I'm pretty sure that Eclipse allows you to add the file to the project, similar to updating the CLASSPATH with that file's location. Rather than constantly chasing files stored in random locations on your system, put them all in a common resource location and point Eclipse at that. Right click on the project and look through the available settings. The Eclipse Wiki and online documentation should help if you can't find it.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Can't Find File Apache Poi

    Quote Originally Posted by darora View Post
    I'm on a Mac and I tried to find the absolute path but I couldn't.
    On a Mac, or any 'nix systems the absolute path would be preceded by a '/' (eg /Users/etc...). To dynamically read the file (eg, if the file may change or your project used on a different computer) you might wish to prompt the user (via command line or JFileChooser). Alternatively, like Greg said if this is a file that is required by the project you might want to add it to your project.

  6. #6
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Excel Files in Netbeans

    I'm currently running Netbeans 8.0 and attempting to use Apache POI to read various .xlsx files. Currently, I'm getting a java.io.FileNotFoundException. I'm using a Mac. What is the correct way to list the file path for my files in Netbeans? Also, is it possible to add the files to my actual project and access them inside the project?

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Can't Find File Apache Poi

    Please don't start a new topic related to the very same problem posted in a previous thread - your threads have been merged. You received help above, what don't you understand about it?

Similar Threads

  1. read the word file without using apache poi jar
    By sivanand in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 21st, 2013, 08:41 AM
  2. Reading multiple columns from an excel file using apache poi 3
    By ramachandra469 in forum Java Theory & Questions
    Replies: 1
    Last Post: May 15th, 2013, 11:01 AM
  3. Apache POI - CREATE_NULL_AS_BLANK - how?
    By Purple01 in forum Java Theory & Questions
    Replies: 3
    Last Post: September 28th, 2012, 06:50 AM
  4. Creating an Excel file using apache poi
    By mija in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: August 17th, 2012, 05:15 AM
  5. Apache POI
    By PineAppleKing in forum What's Wrong With My Code?
    Replies: 10
    Last Post: May 31st, 2011, 12:12 PM

Tags for this Thread