[jboss-user] [Beginners Corner] - Files and Context Paths

yj4jboss do-not-reply at jboss.com
Wed Nov 22 06:51:56 EST 2006


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

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3987860#3987860

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3987860



More information about the jboss-user mailing list