I know this is an OLD thread, but i"m having the same problem. a Runtime error when trying to "OPEN" a file.

public void actionPerformed( ActionEvent evt)
  {
	
	 //filterMap.put(evt.getActionCommand(), ((JCheckBox)evt.getSource()).isSelected()); 
	 if(evt.getActionCommand().equals("export")){
		 String file2Read;
		 file2Read = fileIN.getText();
		//file2Read = "NotConverted2.xls";	 
	  	new BPSepcExporter().BPSReader(file2Read);
	 }
	 //If to check if Open button was hit
	 if(evt.getActionCommand().equals("Open")){
		 //If to make sure something useful was done
		int fIn = BpsFile.showOpenDialog(null);
		if(fIn == JFileChooser.APPROVE_OPTION){
			File file = BpsFile.getSelectedFile();
			fileIN.setText(file.getName());
		}
	 }
  }

public void BPSReader(String fileName){
		//Input control variable- take from GUI options
		List cellDataList = new ArrayList();  
		try {  
			//Create a new instance for FileInputStream class  
  			FileInputStream fileInputStream = new FileInputStream(fileName);  
   			// Create a new instance for POIFSFileSystem class  
  
  			POIFSFileSystem fsFileSystem = new POIFSFileSystem(fileInputStream);  
  
  			//Create a new instance for HSSFWorkBook Class  
  
  			HSSFWorkbook workBook = new HSSFWorkbook(fsFileSystem);  
  			HSSFSheet hssfSheet = workBook.getSheetAt(0);  
   
		 //Iterate the rows and cells of the spreadsheet to get all the datas.  
  			Iterator rowIterator = hssfSheet.rowIterator();  
  				while (rowIterator.hasNext()){  
  					HSSFRow hssfRow = (HSSFRow) rowIterator.next();  
  					Iterator iterator = hssfRow.cellIterator();  
  					List cellTempList = new ArrayList();  
  						while (iterator.hasNext()){  
  							HSSFCell hssfCell = (HSSFCell) iterator.next();  
  							cellTempList.add(hssfCell);
  						}  
  				cellDataList.add(cellTempList);
  				}
  		}  
		catch (Exception e){  
		e.printStackTrace();  
		}
	 printToConsole(cellDataList);
	}

after the exception a bunch of at lines show up, I can post those later if need be. The 2 attached method/constructor methods are the sections where the errors show up. Lines 9 and 27. First in the reader section(27) and then the gui section (9). Now this is reading any file that is not in the same directory as the program, which it was able to do previously.

I've narrowed down where the error is happening and its at line 27 in the posted code. Using a print statement to print whats in fileName, before and after this line I can say that up to that line the code works.

If the path of the filename cannot be found relative to the directory in which the program is executing, you'll need to provide a more complete path to the file. You didn't post the error message, but it sounds like a FileNotFoundException?

java.io.FileNotFoundException: Bob2.xls (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at BPSepcExporter.BPSReader(BPSepcExporter.java:183)
at BpsExportGUI.actionPerformed(BPSepcExporter.java:134)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Does that help? and Yes I think it was an FileNotFoundException

Yeah, that's simply a path error. You'll need to supply a full path to the file unless it's in a sub-directory of your program folder.

its not a sub-directory and I don't want it to be. The goal is to have the program run and open a file from any where, including a networked drive

That's fine. You'll just need to supply the full path to the resource in that case.

Ok, then how do I go about doing this? will a array be used, and then split the array up to something the language can handle?

I'm not following what you mean with arrays and splitting anything. You simply need to supply the full path to the file.

c:/whateverDir/whateverFile.xls
//someNetworkLocation/whateverDir/whateverFile.xls

I thought that in order for Java to understand where the file was I would have to get the path first, then break it up. If that is not the case then excellent. Since the full path needs to be provided, then how do I go about doing it with my current open file button/listener? Is their just something I need to add to it in order to load the full path or do I need a whole different setup?

You already have a File object from the open dialog, so use file.getPath() instead of file.getName().

You sir.. or ma'am, are a genius and my hero.


Solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.