Skip to Content
0
Former Member
May 27, 2008 at 09:55 PM

FileNotFoundException with componentRequest.getWebResourcePath()

60 Views

Hi All,

Im trying to read my an excel file stored in a folder called resources under "dist" in the project structure. Following is the method in my component for reading the excel file.

The code is throwing error on :

InputStream fs = new FileInputStream(FileURL);

The error is "FileNotFoundException Occured java.io.FileNotFoundException: /irj/portalapps/NewJcoTest/resources/Book3.xls "

public void readfile(){
 try{
     System.err.println("inside try");
     IPortalComponentRequest componentRequest = (IPortalComponentRequest) this.getRequest();
     String FileURL = componentRequest.getWebResourcePath() + "/resources/Book3.xls";
				
     InputStream fs = new FileInputStream(FileURL);
     System.err.println("created filesystem");
				
     HSSFWorkbook wb = new HSSFWorkbook(fs);
     System.err.println("created workbook");
     HSSFSheet sheet = wb.getSheetAt(0);
     System.err.println("picked up sheet");
				
     for (Iterator rit = sheet.rowIterator(); rit.hasNext(); ) {
          HSSFRow row = (HSSFRow)rit.next();
	System.err.println("first FOR printing row Avaya1:- " + row);
	   for (Iterator cit = row.cellIterator(); cit.hasNext(); ) {
	     HSSFCell cell = (HSSFCell)cit.next();
	        System.err.println("second FOR printing cell Avaya2:- " + cell.getStringCellValue()+"\t");
	   }
      }
}catch(FileNotFoundException fnf){
 System.err.print("FileNotFoundException Occured " + fnf.toString()); 	
 }catch(Exception e){
System.err.print("Exception Occured " + e.toString()
}

}

Please advice.