1

I don't know why but I cannot seem to get my head wrapped around paths in Java (I'm a Linux admin so that is my reference point). I have the following directory tree:

KCBSEvents
    src
        KCBSEvents
            <Java class source files>
        KCBSEvents.Images
            <jpg Image files>
        KCBSEvents.resources
             <resource files>

In a class in KCBSEvents>src>KCBSEvents I am trying to read a jpg file from KCBSEvents.Images.

File file=new File("../KCBSEvents.Images/KCBSLogo.jpg");
try {
        image=ImageIO.read(file);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

I am getting a can't read input file exception. Can someone help me figure out what the correct path should be? I don't understand why the path is wrong. The '..' goes up one level to 'src' and that is where KCBSEvents.Images lives. That jpg file is indeed in that directory. TIA.

Wt Riker
  • 514
  • 12
  • 24
  • Can you please post the exception. – Prashant Dec 15 '16 at 11:36
  • post the definition of read method as well. On which line is the exception? – Amita Dec 15 '16 at 11:39
  • The reverenced duplicate creates an InputStream object. Doesn't ImageIO.read require a File object? – Wt Riker Dec 15 '16 at 14:00
  • Here is the exception: – Wt Riker Dec 15 '16 at 14:04
  • Here is the part of the traceback that can fit. Line 56 is the ImageIO.read line: javax.imageio.IIOException: Can't read input file! at javax.imageio.ImageIO.read(Unknown Source) at KCBSEvents.SplashScreen.initialize(SplashScreen.java:56) at KCBSEvents.SplashScreen.(SplashScreen.java:20) at KCBSEvents.SplashScreen$1.run(SplashScreen.java:30) – Wt Riker Dec 15 '16 at 14:12

0 Answers0