How to use get getResourceAsStream

Gday all,
I gave up trying to comprehend the API doco and tutorials on the How to use get getResourceAsStream. I don't care how the class loader locates resources... I just it to work. Now!
Here's what works... and what doesn't work...
package krc.geometry;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.IOException;
import krc.utilz.io.RuntimeIOException;
abstract class GeometryProperties {
  private static Properties properties = new Properties();
  static {
    try {
      // properties.load(new FileInputStream("c:/java/home/src/krc/geometry/Geometry.properties")); //WORKS
      // properties.load(new FileInputStream("c:/java/home/classes/krc/geometry/Geometry.properties")); //WORKS
      // properties.load( (new Object()).getClass().getResourceAsStream("krc/geometry/Geometry.properties")); //DOES NOT WORK
      // properties.load( (new Object()).getClass().getResourceAsStream("krc.geometry.Geometry.properties")); //DOES NOT WORK
      // properties.load( (new Object()).getClass().getResourceAsStream("Geometry.properties")); //DOES NOT WORK
      // properties.load( (new Object()).getClass().getResourceAsStream("krc\\geometry\\Geometry.properties")); //DOES NOT WORK
      properties.load( (new Object()).getClass().getResourceAsStream("/krc/geometry/Geometry.properties")); //WORKS
    } catch(IOException e){
      throw new RuntimeIOException("Failed to load GeometryProperties: " + e.getMessage());
  static Properties get() {
    return properties;
  static String getProperty(String key) {
    return properties.getProperty(key);
  public static void main(String... args) {
    System.out.println(GeometryProperties.getProperty("format.double"));
}I hope someone finds this helpful someday.
Some related links are:
http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)
http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#getSystemResourceAsStream(java.lang.String)
http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#getSystemClassLoader()
http://www.google.com.au/search?hl=en&q=getResourceAsStream+tutorial&meta=&btnG=Google+Search
http://rachel.sourceforge.net/tutorial.html
http://forum.java.sun.com/thread.jspa?threadID=5227823&messageID=9928698
PS: I think the API has ludicrously complicated explanation of something which can be explained succinctly by example... It's a classic case of a "correct" description which only makes sense once you already know how it works. Whomever wrote that one gets 3 out of 10 stars from me... ie No bananas.
Cheers. Keith.
Edited by: corlettk on Dec 2, 2007 9:28 AM - typos.

I've noticed a good google hit rate on this forum, especially on threads with meaningful a subject lines... That's how I found these forums in the first place... I'm hoping that posting solutions and comments here (as well as the occasional question) will make them available to others from google... I doubt that any site I created would earn the same "front page" status as Sun's site.
Besides, doesn't it still cost money to setup a blog or your own homepage?
I admit I'm intrigued despite myself... I'm aware that both http://www.joelonsoftware.com/ and http://www.dreamincode.net/ (and problably many others) started as little personal blogs.

Similar Messages

  • How to use get() method of hashmap in jsp

    Hi,
    Iam using hashMap in action form from which I want to retrieve the value by giving the key in jsp page.
    ex: HashMap m = new HashMap();
    m.add("key", "value");
    String v = m.get("key");
    I want to know how implement m.get("key") in jsp without doing iteration.
    Thanks & Regards,
    Nasrin.N

    Hi
    First of all I would say that there is no "add" method for Hashmap, its put
    secondly try this
    <bean:write property="map_key" name="mapSetterGetter" />

  • How to use get column name.vi in SQL toolkit 2.0?

    Due to the vi "get column name.vi" paremeters,no table name has connected to the vi. So, I want to ask how to use this vi for gain one column name of a table. Maybe there are some other ways to solve column name getting.
    Thanks.

    Thanks!
    Error 4101 Description:
    Execute SQL - The connection, statement, or query handle you provided is not valid.
    I don't just used the toolkit in a while,now, I am developing a irrigation system. For the table field names defined by users,column names must be known before any select operations. Do you have any other good idea about drawing out the columnname parameters?
    As you know, a valid DSN and table have been also available. The database I used is Access. The bad thing to me is that there is no any text information gotten. And I think, it may be some problems in connection way which I don't find out.
    Really appreciated by your reply.
    Could you give me some example in the aspect?
    Thank you again.

  • How to use Get-WebHandler,Get-Website command in Powershell 2.0 of 64 bit system ?

    Hi,
    I am trying to use  Get-WebHandler , Get-Website  in Powershell 2.0 version .It is throwing error as below
    "  Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to
    the following error: 80040154  "
    It is working fine in powershell 4.0 version but not working  in powershell 2.0 version.Can anyone suggest solution to this.
    Some IIS commands which are working fine in Powershell 4.0 , are throwing above error in Powershell 2.0 version . Please suggest me the best solution to fix this issue

    this is a duplicate post. I suspected the same
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/87655dab-84ea-4e1d-8b43-b5c193f8702a/some-powershell-40-version-iis-commands-not-working-in-powershell-20-?forum=winserverpowershell#352bfa16-8c03-49fd-825c-89e3c150522b
    Indeed yeah we need to import module
    Regards Chen V [MCTS SharePoint 2010]

  • How to use get-mailbox -Identity to select or target multipul users.

    When I use this statement, the command executes just fine, and all is while.
    Get-Mailbox user1 | Search-Mailbox -SearchQuery 'Attachment:"Query1"' -targetmailbox "admin" -targetfolder "test" -searchdumpster -loglevel full
    what also works is this:
    Get-Mailbox -Server Server1 | Search-Mailbox -SearchQuery 'Attachment:"Query1"' -targetmailbox "admin" -targetfolder "test" -searchdumpster -loglevel full }
    However I need to target about 10 user mailboxes for this search (and larger a delete\purge) I'd rather not run the same command 10times just changing the user name, is there a way to put that all on one search command?

    Run your command like this:
    "User1","User2","User3","User4","User5","User6","User7","User8","User9","User10" | Get-Mailbox | Sort Name |
    Search-Mailbox -SearchQuery
    'Attachment:"Query1"' -targetmailbox
    "admin" -targetfolder
    "test" -searchdumpster
    -loglevel full
    That will iterate through each mailbox individually.  You can also put all the names into a txt file (one alias to a row) and use
    Get-Content <filename> instead of the list of aliases - that makes it simpler to update your list.
    Get-Content <filename> | Get-Mailbox | Sort Name | Search-Mailbox
    -SearchQuery 'Attachment:"Query1"'
    -targetmailbox "admin"
    -targetfolder "test"
    -searchdumpster -loglevel full

  • AppleScript how to use "get" for field information and drop-down boxes?

    Hi all,
    First post.
    Looking to use the "get" function or similar for getting information in a list or from a drop-down box or a field.
    Example, you open keychain, open the info. for a cert and want to read the currently selected trust setting for "When using this certificate" drop-down.
    Or, you want to check the Common Name field under details.
    How would I return these specific values?
    Thank you,
    -b

    The exact question being asked here: http://forum.soft32.com/mac/select-table-row-ftopict101735.html
    But, that doesn't work with the latest AppleScript.

  • How to use get im different class?

    Hello, I am new to this java. I need your help, please
    I have Rental class that I use for my RentalApplication to run my Number of items rented & Total of Sale.
    However it gives me 0 instead of the number. Where did I write wrong code?
    public class Rental {
         //Declare variables
         public static final double COST_OF_NEW_RELEASES = 2.25;
         public static final double COST_OF_REGULAR_VIDEO = 1.00;
         public static final double COST_OF_DVDS = 2.98;
         public static final double COST_OF_GAMES = 4.50;
         private int NewReleases;
         private int RegularVideo;
         private int Dvds;
         private int Games;
         private Date timeOfSale;
         private int customerNumber;
         private String customerRental;
         //Constructor method
         public Rental(int theCustomerNumber) {
              timeOfSale = new Date();
              customerNumber = theCustomerNumber;
              NewReleases = 0;
              RegularVideo = 0;
              Dvds = 0;
              Games = 0;
              System.out.println(customerRental = "\nCustomer Number " + customerNumber);
         public Rental(
              int theNumberOfNewReleases,
              int theNumberOfRegularVideo,
              int theNumberOfDvds,
              int theNumberOfGames) {
              this.NewReleases = theNumberOfNewReleases;
              this.RegularVideo = theNumberOfRegularVideo;
              this.Dvds = theNumberOfDvds;
              this.Games = theNumberOfGames;
              this.timeOfSale = new Date();
         //Getters
         public int getNumberOfNewReleases() {
              return NewReleases;
         public int getNumberOfRegularVideo() {
              return RegularVideo;
         public int getNumberOfDvds() {
              return Dvds;
         public int getNumberOfGames() {
              return Games;
         //Other Methods
         public double rentalCost() {
              * Rental Cost()
              * creation date ("2/5/03" 1:30PM)
              return NewReleases * COST_OF_NEW_RELEASES
                   + RegularVideo * COST_OF_REGULAR_VIDEO
                   + Dvds * COST_OF_DVDS
                   + Games * COST_OF_GAMES;
         public String getCustomerRental() {
              return customerRental;
         public int totalAmountRented() {
              return NewReleases + RegularVideo + Dvds + Games;
         public Date getTimeOfSale() {
              return timeOfSale;
         public String getFormatteddatetimeOfSale() {
              DateFormat dateFormat = DateFormat.getDateInstance();
              return dateFormat.format(timeOfSale);
         public String getFormattedRentalCost() {
              * rentalCost()
              * creation date ("1/30/03" 1:30PM)
              NumberFormat dollarFormat = NumberFormat.getCurrencyInstance();
              return dollarFormat.format(rentalCost());
         public String toString() {
              String classDescription = "Thank You for renting";
              classDescription += " ";
              classDescription += "\nRental" + "[";
              classDescription += "New Releases = ";
              classDescription += NewReleases;
              classDescription += ", Number of Regular Video = ";
              classDescription += RegularVideo;
              classDescription += ", Number of DVDs = ";
              classDescription += Dvds;
              classDescription += ", Number of Games = ";
              classDescription += Games;
              classDescription += "]" + ", \n[" + "Time of Sale = ";
              classDescription += getFormatteddatetimeOfSale();
              classDescription += ", Rental Cost = ";
              classDescription += getFormattedRentalCost();
              classDescription += "]";
              return classDescription;
         public static void main(String[] args) {
              Rental theRental;
              theRental = new Rental(3, 1, 3, 1);
              System.out.println(theRental.toString());
         * Method findRentalItems.
         * @param thevideoId
         * @return RentalItems
         public static RentalItems findRentalItems(String thevideoId) {
              return null;
    This is my RentalApplication
    public class RentalApplication
         public static void main(String[] args)
              Rental theRental;
              RentalItems theRentalItems;
              VideoStore theVideoStore = new VideoStore();
              int customerNumber = 1;
              boolean newCustomer = true;
              boolean moreLookUps = true;
              String thevideoId;
              NumberFormat numberFormat = NumberFormat.getCurrencyInstance();
              DateFormat dateFormat = DateFormat.getDateTimeInstance();
              while (newCustomer)
                   theRental = new Rental(customerNumber);
                   while (moreLookUps)
                        thevideoId = JOptionPane.showInputDialog("Enter Video Id's");
                        theRentalItems = RentalItems.findRentalItems(thevideoId);
                        System.out.println(theRentalItems.displayRentalItems());
                        moreLookUps = getOption("Another Videos?");
                   theVideoStore.addRental(theRental);
                   System.out.println("Time of sale: "+ dateFormat.format(theRental.getTimeOfSale())
                                       + "\tNumber of items rented "
                                       + (theRental.totalAmountRented())
                                       + "\tTotal of Sale: "
                                       + numberFormat.format(
                                            theRental.rentalCost()));
                   newCustomer = getOption("Another Customer");
                   moreLookUps = true;
                   customerNumber++;
              System.out.println(theVideoStore.displayVideoStore());
              System.exit(0);
         public static int readInt(String prompt) {
              return Integer.parseInt(JOptionPane.showInputDialog(prompt));
         public static boolean getOption(String prompt) {
              int theNum;
              theNum = JOptionPane.showConfirmDialog(null, prompt);
              return (theNum == 0);

    In your RentalApplication main() method, you do the following:
    theRental = new Rental(customerNumber);which calls the
    public Rental(int theCustomerNumber)constructor.
    In that constructor, you initialize
    NewReleases = 0;
    RegularVideo = 0;
    Dvds = 0;
    Games = 0;But nowhere do you ever adjust those values. So the reason you're getting 0 back, I believe, is because that's what you set them to.

  • How to use get Spread sheet

    Hi All
    Can anybody help be in how can I open a spread shheet when I click a button in SWING .`
    Also Can i edit the spreadsheet so that next time when I click its cpomes as uppdated spreadsheet.
    Thanks

    Hi my friends,
    This page should use style css/wine.css, for example, but it is not doing this when I put it as a portlet. How should to stay my provider.xml file? When I must put the css directory?
    Thanks,
    Carla.

  • How to use "GET TIME"?

    Dears,
    2 parts code as following:
    Ex 1:
    DATA: GC_DATUM  TYPE  SY-DATUM,
               GC_UZEIT    TYPE SY-UZEIT.
    GET TIME.
    GC_DATUM   = SY-DATUM.
    GC_UZEIT = SY-UNEIT.
    Ex 2:
    DATA: GC_DATUM  TYPE  SY-DATUM,
                 GC_UZEIT  TYPE SY-UZEIT.
    GC_DATUM   = SY-DATUM.
    GC_UZEIT = SY-UNEIT.
    About  the value of  "GC_DATUM" and    " GC_UZEIT" , Is there difference between Ex 1 and Ex2?
    I have test it , It seems that there is no difference.
    If there is no difference really, could you please tell me what's use of " GET TIME "?
    Thanks in advance.
    Best regards,
    Lily

    Hi,
    Follow up this:
    Use the function module
    BDL_GET_CENTRAL_TIMESTAMP
    OR
    if suppose data field contains 20080130200007.6870490 .
    concatenate data+0(4)
    data+4(2)
    data+6(2)
    into date
    separated by '-'.
    concatenate data+8(2)
    data+10(2)
    data+12(2)
    into temp_time
    separated by ':'.
    concatenate temp_time
    data+15(7)
    into time
    separated by '.'.
    Thanks,
    srii...

  • How to use "GET" to fetch data and insert it in Edge?

    I have a compostion in which I need to insert a name  with "GET". How can I do that. This is new territory to me,

    Json data type would be an ideal option.
    jquery reference - http://api.jquery.com/jQuery.getJSON/
    Nice example here rom gotoandlearn - http://www.gotoandlearn.com/play.php?id=168
    Darrell

  • How to use dynamic selection screen inputs in main program

    hi all,
      its a report where in it calls one dynamic selection screen( user need to enter the parameters here) after that i need to use those inputs for some check, can any buddy help how to use/ get that input parameters into main program.
    regards,
    vara..

    Hi,
    i think u have created that dynamic selection screen in seperate program and calling to ur main program.instead of that u just create that synamic selection screen program as include program and include it in ur main program.
    or u need to use set/get parameter id concept.
    rgds,
    bharat.

  • Using GET-SMBShare to check if share exist

    I understand how to use get-smbshare to check if a share exist or not.  My problem I am having is if it doesn't I want my function to create the share using the net-smbshare command.  I can do this with the New-Item for directories, etc. 
    Just can't figure a way to take the response that command gives when it doesn't exist.
    For example with my New-Item commands I would do something like this:
    IF (!(GET-SMBShare -Name ShareName))
    New-SMBShare -Name ShareName -Path C:\Path -Description "A Share"
    I can create the share without any issues but I want to make sure that share doesn't exist and would like to stick to Get-SMBShare command if possible. If the share doesn't exist it errors out like it should cause it isn't there. How do I get the GET-SMBShare
    command when it returns that it doesn't exist a value that I can read?
    For instance:  If (!(Test-Path -Path C:\Path))  returns a True and I can continue with my function.
    Kristopher Turner | Not the brightest bulb but by far not the dimmest bulb.

    Simple:
    if(!(Get-SMBShare
    -Name
    ShareName -ea 0)){
        New-SMBShare
    -Name
    ShareName -PathC:\Path
    -Description
    "A Share"
    It will get easier once you leaner PowerShell. THe syntax is easy but your eyes have to get used to what is missing and learn hw to induce behaviors you want.
    ¯\_(ツ)_/¯

  • When I login on my When I sign in to a site on my ipad using my email address as ID a short cut of my email address comes up. How can I get rid of it?

    When I sign in to a site on my iPad using my email address as ID a short cut of my email address comes up. How can I get rid of it?

    You can edit keyboard shortcuts in Settings>General>Keyboard>Shortcuts>Edit.

  • I downloaded an album on itunes using my new itouch; but it's only allowing me to put three songs at any one time into the music app...how can i get it to just move them all in there?

    i downloaded an album on itunes using my new itouch; but it's only allowing me to put three songs at any one time into the music app...how can i get it to just move them all in there?

    hi philly, thanks for getting back to me, especially on such a busy day.
    I don't think that's quite the issue though. I bought an album and it appears in 'my purchases' within the itunes app. Yet, in order to listen to the music, i must use the 'music' app and in this application, there are only three tracks displayed at any one time from my downloaded album.
    I can 'download all' from the 'my purchases' section but that still doesn't help, it just keeps the last three tracks downloaded in the music app.
    I have the 'icloud' enabled and wondered if it had anything to do with that.
    i have successfully downloaded another full album totally into the music app, but this first album is causing me problems.

  • HT201248 My email address associated with my Apple ID on my iPad has been turned off from the ISp (U.S. army).   I have a new gmail account with a new Apple ID. How do I get my iPad to use my gmail account?

    Help. My old @us.army.mil email address was terminated by the army. I used that address to register my first apple id account on my iPad. I can't remember my original Apple ID number and if I ask to reset my password, Apple sends the reset link to my old non-working email address. I have a new gmail address and a new Apple ID number associated with that address. How do I get my iPad to use my new gmail address and new apple ID number?  Remember, I can't log out of my old account because I can't remember the password. Amd Apple will only reset the password by sending a link to my old, non functioning army email account. ( I hate army webmail for canceling all retired military email accounts). John Marc
    <Personal Information Edited By Host>

    Hi John,
    You can change the email address associated with an Apple ID using the steps in this article -
    Change your Apple ID - Apple Support
    Thanks for using Apple Support Communities.
    Best,
    Brett L 

Maybe you are looking for

  • Warranty void on Apple engraved products?

    Can anyone help me? I'm thinking about buying a 3rd Gen Nano from the online Apple store for my daughter for Christmas and getting it engraved, but I've been informed recently that if I have it engraved it will void the warranty, is this correct? I h

  • Webi Error - Driver not capable

    Hello, One of our users is getting "Driver not capable" error on 1 webi report, but can run another without the error. These 2 reports come off seperate BEx querier. We have BO SP2 FP2.5. SAP authentication is set on BO server and roles are imported.

  • When in Firefox, my taskbar covers the horizontal scroll bar. How do I change it so that it wont?

    When I'm in Firefox, the taskbar at the bottom of the screen hides the horizontal scroll bar. How do I get the scroll bar to be visible?

  • Project/Albums show as having pictures, but won't display the pictures.

    I have a Project and it has two albums listed (indented) underneath it. I have moved them around a bit to put them in different folders, and now the pictures won't display.  By that I mean that if I mouse over the project, a popup (or flyover) says t

  • Unable to update Caption field

    Hello; Wondering if anybody else has seen this problem before... I've spent the evening updating caption fields only to have Aperture display a "loading..." message over the photo and then return the previous caption field text. It's as if the Apertu