Results 1 to 3 of 3
  1. #1
    Vampire5 is offline Member
    Join Date
    Aug 2012
    Posts
    20
    Rep Power
    0

    Question How to read Image files from folder

    I have a project where the directories look like this

    Java Code:
    /src                                              // Where I have all my source-code
    /src/org/shockassault/
    /src/org/shockassault/graphics/
    /src/org/shockassault/input/
    /res                                              // Where I have all my images
    /res/textures/Simple_Tile.jpg          // The file image I want to access
    How would I access that image from the /src/org/shockassault/graphics/ (where the class is)? There is a way, but I think it has to do with how I use the Java Compiler (javac) by adding a classpath or something like that.

    The reason I ask is that I was following a tutorial, but this tutorial does stuff in Eclipse, and I don't use Eclipse nor to I plan to, and he used a method as such:
    Java Code:
    BufferedImage image = ImageIO.read(Texture.class.getResource("/texture/Simple_Tile.jpg"));
    Here's the link to the video tutorial if you need it to see what he does in Eclipse: 3D Game Programming - Episode 15 - Textures + More! - YouTube

    Thanks!

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: How to read Image files from folder

    In Eclipse you would add res as a source directory.
    The equivalent from the command line would be to add res into the classpath at execution time (not compile time).

    java -cp<your other classpath things>:<path to res> <your main class>
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Vampire5 is offline Member
    Join Date
    Aug 2012
    Posts
    20
    Rep Power
    0

    Default Re: How to read Image files from folder

    Thanks a ton, I very much dislike it when tutorials only do things for a specific IDE, this clarifies things a bunch for me. Thanks!!!

Similar Threads

  1. Replies: 0
    Last Post: 06-11-2013, 07:36 AM
  2. Replies: 0
    Last Post: 02-15-2013, 06:04 PM
  3. Which folder do you put image files in
    By ikkyu2 in forum New To Java
    Replies: 1
    Last Post: 10-24-2011, 12:26 AM
  4. Folder & Files
    By Prajin in forum Advanced Java
    Replies: 14
    Last Post: 07-14-2010, 10:31 AM
  5. Replies: 2
    Last Post: 02-20-2009, 07:13 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
  •