0 Replies Latest reply on Nov 22, 2006 6:51 AM by Yogesh

    Files and Context Paths

    Yogesh Novice

      Hello,
      I have a newbie question regarding files and contexts paths.

      I have a CSV file packed in an EAR file which contains a WAR file. The WAR files contains a XHTML files and a CSV file along with other folders such as WEB-INF, META-INF, Style ...etc.

      Via a Managed bean i am trying to read the CSV file using the "OpenCSV" libray.


      
      public void readCSV() throws FileNotFoundException, IOException{
      
       log.debug("enter_readCSV");
      
       path="user.csv";
      
       CSVReader reader = new CSVReader(new FileReader(path));
      
       String [] nextLine;
       while ((nextLine = reader.readNext()) != null) {
      
       User tempUser = new User();
       tempUser.setDisplayName(nextLine[0]);
       tempUser.setUserName(nextLine[1]);
      
       importUserList.add(tempUser);
      
       }
      
      
       }
      
      



      However, though the code works in Eclipse, it fails in JBoss with the following error msg:

      Caused by: java.io.FileNotFoundException: jbosscsv.csv (The system cannot find the path specified)
      
      



      I then changed the code to retrieve the file relative from the local context

      
      public void readCSV() throws FileNotFoundException, IOException{
      
       log.debug("enter_readCSV");
      
       String path = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
      
       path+="/user.csv";
      
       CSVReader reader = new CSVReader(new FileReader(path));
      
       String [] nextLine;
       while ((nextLine = reader.readNext()) != null) {
      
       User tempUser = new User();
       tempUser.setDisplayName(nextLine[0]);
       tempUser.setUserName(nextLine[1]);
      
       importUserList.add(tempUser);
      
       }
      
      
       }
      
      



      Still the same error msg is displayed as follows:

      
      Caused by: java.io.FileNotFoundException: \enforcement\jbosscsv.csv (The system cannot find the path specified)
      
      



      Any idea what could be wrong ??

      Cheers,
      Yogesh