Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Nov 2010

    GetResourceAsStream I NEED HELP

    hi! how do i know if i accessed the file successfully on my res folder?

    InputStream in = getClass().getResourceAsStream("filename");
    // display TRUE if accessed
    //display FALSE if not accessed

    is this correct?

    and what is the proper way of accessing the file?

    getResourceAsStream("/filename"); // with slash


  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Cheshire, UK

    Re: GetResourceAsStream I NEED HELP

    Yes. getResourceAsStream() returns null if the resource could not be opened.

    The file name should always start with a "/". getResourceAsStream() is a method of Class, because it uses the class loader to load the resource. Because of this, a path without a leading "/" is relative to the path (package) of the class, which can lead to confusing results. If the name starts with a "/", then it is relative to the root of the application's JAR file.

    Be careful to match the case of the file name. Some devices are case-sensitive, while some are not. Again, this can lead to confusing results, where your app works on some phones and not others.


Similar Threads

  1. Problem with getResourceAsStream()
    By earamsey in forum Mobile Java General
    Replies: 30
    Last Post: 2010-12-27, 18:59
  2. getResourceAsStream()
    By frasene in forum Mobile Java General
    Replies: 7
    Last Post: 2010-10-05, 19:47
  3. getClass().getResourceAsStream()
    By tanmoy1048 in forum Mobile Java General
    Replies: 5
    Last Post: 2008-09-16, 14:32
  4. write file with getResourceAsStream()
    By saifulhq in forum Mobile Java General
    Replies: 3
    Last Post: 2007-09-26, 14:45
  5. getResourceAsStream problem ?!
    By metebalci in forum Mobile Java General
    Replies: 3
    Last Post: 2005-05-15, 14:57

Posting Permissions

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