Results 1 to 4 of 4
  1. #1
    sbutt is offline Member
    Join Date
    Apr 2009
    Posts
    18
    Blog Entries
    1
    Rep Power
    0

    Default file not found error

    Hi All,
    This is somehow a very basic question, but surprisingly I am stuck in it:(
    I am getting this exception:

    [AirlineBaggageReader] Error:java.io.FileNotFoundException:....

    I am trying to read in my java file [AirlineBaggageReader.java] an xml file [ypsilonBaggage.xml]
    but somehow the class does not able to locate the xml file and hence the exception.

    If you look at the two attached images, you'll get to know the directory structure.

    This is my file reading function

    Java Code:
     private static String readFileAsString(String filePath) 
      {
        File file = new File(filePath);
        int ch;
        StringBuffer strContent = new StringBuffer("");
        FileInputStream fin = null;
          
        
        try {
          fin = new FileInputStream(file);
          while ((ch = fin.read()) != -1)
            strContent.append((char) ch);
          fin.close();
        } catch (Exception e) {
          logger.error("Error:" + e);
        }    
        
            
        return strContent.toString();
      }
    I have called the function with variety of paths but no luck.

    Java Code:
    readFileAsString("/META-INF/xsl/ypsilon/ypsilonBaggage.xml");
    readFileAsString("../../../../../../META-INF/xsl/ypsilon/ypsilonBaggage.xml");
    I am using eclipse IDE and here is the projects .classpath file

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
    	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
    	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
    	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
    	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
    	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    	<classpathentry kind="output" path="target/classes"/>
    </classpath>
    I am using linux for deployment.

    Please help me out?

    Thanks.
    Attached Thumbnails Attached Thumbnails file not found error-yps_1.jpg   file not found error-yps_2.jpg  
    Last edited by sbutt; 07-14-2011 at 06:58 PM.

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default

    Instead of opening it as a file, try using Class (Java Platform SE 6)
    Get in the habit of using standard Java naming conventions!

  3. #3
    sbutt is offline Member
    Join Date
    Apr 2009
    Posts
    18
    Blog Entries
    1
    Rep Power
    0

    Default

    tried this

    Java Code:
    filePath = "ypsilonBaggage.xml"
    
    private static String readFileAsString(String filePath) 
      {
        //File file = new File(filePath);
        int ch;
        StringBuffer strContent = new StringBuffer("");
        //FileInputStream fin = null;
        
           
        try {
          //fin = new FileInputStream(file);
          InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
          while ((ch = is.read()) != -1)
            strContent.append((char) ch);
          is.close();
        } catch (Exception e) {
          logger.error("Error:" + e);
        }    
        
            
        return strContent.toString();
      }
    but got: "Error:java.lang.NullPointerException..."


    also tried

    Java Code:
    InputStream is = this.getClass().getResourceAsStream(filePath)
    and

    Java Code:
    InputStream is = ClassLoader.getSystemResourceAsStream("ypsilonBaggage.xml");
    but same error
    Last edited by sbutt; 07-15-2011 at 11:43 AM.

  4. #4
    sbutt is offline Member
    Join Date
    Apr 2009
    Posts
    18
    Blog Entries
    1
    Rep Power
    0

    Default

    this finally worked...

    Java Code:
    String filePath = "/META-INF/airlineBaggage/ypsilonBaggage.xml"; 
    
    String url = Thread.currentThread().getContextClassLoader().getResource(filePath ).getFile();
    
    logger.debug("FILE URL : " + url);
    thanks.

Similar Threads

  1. javac: file not found Error
    By LimblessQuasar in forum New To Java
    Replies: 3
    Last Post: 06-11-2011, 09:41 AM
  2. No Class Def Found Error:
    By fithous in forum Java Applets
    Replies: 0
    Last Post: 04-02-2009, 05:30 PM
  3. No JVM found error
    By rocky05 in forum New To Java
    Replies: 1
    Last Post: 01-27-2009, 03:41 PM
  4. no jre,jvm found error
    By rocky05 in forum Eclipse
    Replies: 2
    Last Post: 01-27-2009, 03:38 PM
  5. symbol not found error
    By rmartyce in forum New To Java
    Replies: 1
    Last Post: 05-23-2008, 05:58 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
  •