Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: File not getting workspace

  1. #1
    Member
    Join Date
    Jun 2012
    Location
    Uppsala, Sweden
    Posts
    36
    Thanks
    10
    Thanked 1 Time in 1 Post

    Post File not getting workspace

    Hi! (Sorry for the bad title. English is not my native language and I didn't know how to put it.) I have a problem with getting an image with ImageIO.read(File file). I have the following code to get the image.

    try {
    	File file = new File("/res/entities/player/human.png");
    	System.out.println(file.getAbsolutePath());
    	image = ImageIO.read(file);
    } catch (IOException e) {
    	e.printStackTrace();
    }

    The problem is, the file does not get the workspace path before the given path.

    Instead of the path being:

    C:/...path to workspace.../res/entities/player/human.png

    It is:

    C:/res/entities/player/human.png

    This has never happened before and I dont know what to do.

    There error is also only in this program. It works in all my other projects!

    Please help me!
    Last edited by Dr.Code; August 24th, 2012 at 02:07 AM.


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: File not getting workspace

    Try

    File file = new File("res/entities/player/human.png");

    ie without the leading /. At the moment the file name will be resolved to something at the top of the current drive (C).

  3. The Following User Says Thank You to pbrockway2 For This Useful Post:

    Dr.Code (August 24th, 2012)

  4. #3
    Member
    Join Date
    Jun 2012
    Location
    Uppsala, Sweden
    Posts
    36
    Thanks
    10
    Thanked 1 Time in 1 Post

    Default Re: File not getting workspace

    Thank you! it worked!

  5. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: File not getting workspace

    You're welcome.

  6. The Following User Says Thank You to pbrockway2 For This Useful Post:

    Dr.Code (November 4th, 2012)

Similar Threads

  1. why i cannot use this class if working with another workspace?
    By piulitza in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 14th, 2012, 03:04 PM
  2. Replies: 1
    Last Post: March 22nd, 2011, 06:59 PM
  3. Replies: 10
    Last Post: January 12th, 2011, 05:48 AM
  4. insert(embed) a file object (.txt file) in MS excel sheet using java.
    By jyoti.dce in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 12th, 2010, 08:16 AM
  5. Replies: 8
    Last Post: January 6th, 2010, 09:59 AM

Tags for this Thread