getResourceAsStream() doesn't work

Hi;

The following code works:

System.IO.Stream stream = Class.ToType(SystemWrapper.class).get_Assembly().GetManifestResourceStream("resources.resources_en_US.properties");

This doesn't:

java.io.InputStream is = SystemWrapper.class.getResourceAsStream("resources.resources_en_US.properties");

Why (SystemWrapper is the class the above calls are in.)

thanks - dave


Answer this question

getResourceAsStream() doesn't work

  • Vasudeva

    Hi David,
    I tried this method and it works for me if I follow this guideline...

    Remember that resource names are resolved relative to the package of the class whose Class object is used to load the resource. Thus, if your application is in package somepackage, and your resource resource1 is in a subfolder dir1, then you need to run vjsresgen.exe from the parent folder of the somepackage folder, so that the resource name gets stored as somepackage.dir1.resource1."

    "When converting resources located in a directory hierarchy, vjsresgen must be run from the root of this hierarchy."

    "If your class is defined in package somepackage and d:\temp\Class1.java then you resources must be stored under d:\temp\sompackage folder .

    Again i would recommend to go through this article. The section 4.1     " Resources file in the same directory" of this article addresses your issue well.

    Please post back if you face any other issue.

    Thanks.


  • Jay Gattani

    Hi;

    I created a class with no namespace and tried
    java.io.InputStream is = Dummy.class.getResourceAsStream("resources.resources_en_US.properties");

    Same problem. So something is not working right here.

    Also, I think the exception shows a bug because if it can't find the resource it should be some ResourceNotFound type exception.

    - thanks - dave


  • adkent

    You may know how to create resouce files if you open J++ project including *.properties file by Visual Studio .NET. VS automatically converts the resouce file into VJ# style.

    Kazuya Ujihara

  • DivyaNSingh

     DavidThi808 wrote:
    Hi;

    I created a class with no namespace and tried
    java.io.InputStream is = Dummy.class.getResourceAsStream("resources.resources_en_US.properties");

    Same problem. So something is not working right here.

    Also, I think the exception shows a bug because if it can't find the resource it should be some ResourceNotFound type exception.

    - thanks - dave


    Hi David,
    Can you please write here that where you code file and .properties files are saved Are they both saved in the same directory or sub directories
    The issue i believe is the complex logic invloved in locating the resources. This logic is very much dependent on directory hierarchies.

    I guess, in above code snippet, if i use "resources_en_US.properties" instead of  "resources.resources_en_US.properties" then it should work.

    Thanks.



  • lavrinenkoe

    Hello Ujihara-san;

    Unfortunately in my case I need common source for java and .net so I have to use my resources.properties files.

    domo arigato - dave

  • getResourceAsStream() doesn't work