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);} } }


Reply With Quote