Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor binsint's Avatar
    Join Date
    Nov 2010
    Posts
    118
    hi! how do i know if i accessed the file successfully on my res folder?

    InputStream in = getClass().getResourceAsStream("filename");
    if(in!=null)
    {
    // display TRUE if accessed
    }
    else
    {
    //display FALSE if not accessed
    }

    is this correct?

    and what is the proper way of accessing the file?

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

    thanks?

  2. #2
    Registered User grahamhughes's Avatar
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,394
    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.

    Graham.

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
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved