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); } }
Caused by: java.io.FileNotFoundException: jbosscsv.csv (The system cannot find the path specified)
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); } }
Caused by: java.io.FileNotFoundException: \enforcement\jbosscsv.csv (The system cannot find the path specified)