Results 1 to 3 of 3
  1. #1
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    272
    Rep Power
    7

    Default File not found IO

    Hi,


    I have an issue trying to read a file. Iam getting a file not found ex, but the file seems to be there.
    This is my project




    This the code that is loading the file.

    Java Code:
     public GATEApplication(String appPath) {
    		try {
    			loadGATEApplication(appPath);
    			corpus = Factory.newCorpus("mainCorpus");
    			application.setCorpus(corpus);	
    		} catch (GateException e) {
    			e.printStackTrace();
    		}
    	}
    
    	/**
    	 * Loads the .gapp file to GATE
    	 * 
    	 * @param path the .gapp file path
    	 */
    	private void loadGATEApplication(String path) {
    		try {
    			Gate.init();	// must run first before any GATE API calls can be made.
    			ClassLoader classLoader = getClass().getClassLoader();
    			File file = new File(classLoader.getResource(path).getFile());
    			System.out.println(file.getPath());  // the path is correct
    			application = (CorpusController) PersistenceManager
    					.loadObjectFromFile(file);	// exception thrown here
    		} catch (GateException | IOException e) {
    			e.printStackTrace();
    		}
    	}
    I test the constructor like this:

    Java Code:
     public static void main(String[] args) {
    		GATEApplication g = new GATEApplication("GATE applications/film_paum.gapp");
    		//File file = new File("ML_Model/GATE applications");
    		//for(String fileNames : file.list()) System.out.println(fileNames);
    the stack trace
    Java Code:
     java.io.FileNotFoundException: C:\Users\Overlord\workspace\Sentiment%20Analysis%20ML%20App\bin\GATE%20applications\film_paum.gapp (The system cannot find the path specified)
    	at java.io.FileInputStream.open0(Native Method)
    	at java.io.FileInputStream.open(Unknown Source)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    	at java.net.URL.openStream(Unknown Source)
    	at gate.util.persistence.PersistenceManager.isXmlApplicationFile(PersistenceManager.java:1013)
    	at gate.util.persistence.PersistenceManager.loadObjectFromUrl(PersistenceManager.java:857)
    	at gate.util.persistence.PersistenceManager.loadObjectFromFile(PersistenceManager.java:831)
    	at gate_resources.GATEApplication.loadGATEApplication(GATEApplication.java:87)
    	at gate_resources.GATEApplication.<init>(GATEApplication.java:67)
    	at gate_resources.Test.main(Test.java:8)
    Exception in thread "main" java.lang.NullPointerException
    	at gate_resources.GATEApplication.<init>(GATEApplication.java:69)
    	at gate_resources.Test.main(Test.java:8)
    but the path on the exception is correct and the file is there. I don't see why this is happening.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: File not found IO

    Is it possible the API doesn't like spaces in the path name. I noticed the exception is showing spaces replaced with %20.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    272
    Rep Power
    7

    Default Re: File not found IO

    Quote Originally Posted by jim829 View Post
    Is it possible the API doesn't like spaces in the path name. I noticed the exception is showing spaces replaced with %20.

    Regards,
    Jim
    That was the issue.. Thanks

Similar Threads

  1. File not found where I put it
    By Captain Bemo in forum New To Java
    Replies: 1
    Last Post: 04-08-2014, 09:14 PM
  2. file not found
    By frank_lin2009 in forum New To Java
    Replies: 4
    Last Post: 06-23-2013, 04:18 AM
  3. Replies: 1
    Last Post: 07-28-2011, 07:50 PM
  4. File not found when using jar
    By nandj987 in forum New To Java
    Replies: 4
    Last Post: 02-22-2011, 01:54 PM
  5. file not found
    By smartshahezad in forum JDBC
    Replies: 2
    Last Post: 03-04-2010, 11:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •