Java - Working with Properties-VBForums
Results 1 to 3 of 3

Thread: Java - Working with Properties

Hybrid View

  1. #1

    Thread Starter
    Dazed Member Dillinger4's Avatar
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,415

    Java - Working with Properties

    In later sections i am going to show how you can restrict access to web pages using http based authorization. Properties will be integrated into this application so i wanted to start with some of the easier parts. Working with Properties is quite easy. The following code simply writes three properties to a file in name:value pair combinations then reads them back printing them on the command line.
    Code:
     
     import java.io.*; 
     import java.util.*; 
    
     class XmlProp{
      public static void main(String[] args) {
      try{
      OutputStream fos = new FileOutputStream("C:\\Passwords"); 
      Properties pws = new Properties();
      pws.setProperty("Red","6546");
      pws.setProperty("Blue","9878");
      pws.setProperty("Green","5609");
     
      pws.store(fos,"Passwords"); 
      Enumeration pns = pws.propertyNames(); 
       while(pns.hasMoreElements()){
        String key = (String) pns.nextElement();
        String prop = pws.getProperty(key); 
        System.out.println("key:value " + key + ":" + prop);
        }
       }catch(IOException io){System.err.println(io);}
      }
     }

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Java - Working with Properties

    Is Properties a class in Java, or are you creating this yourself?

  3. #3

    Thread Starter
    Dazed Member Dillinger4's Avatar
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,415

    Re: Java - Working with Properties

    Posted by System_Error

    Is Properties a class in Java, or are you creating this yourself?
    In Java. It's found in the java.util package. It extends java.util.Hashtable

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.