List of usage examples for java.util Properties put
@Override public synchronized Object put(Object key, Object value)
From source file:PropDemo.java
public static void main(String args[]) { Properties capitals = new Properties(); capitals.put("Illinois", "Springfield"); capitals.put("Missouri", "Jefferson City"); capitals.put("Washington", "Olympia"); capitals.put("California", "Sacramento"); capitals.put("Indiana", "Indianapolis"); Set states = capitals.keySet(); for (Object name : states) System.out.println(name + " / " + capitals.getProperty((String) name)); String str = capitals.getProperty("Florida", "Not Found"); System.out.println("The capital of Florida is " + str + "."); }
From source file:MainClass.java
public static void main(String args[]) { Properties prop = new Properties(); prop.put("a", "1"); prop.put("b", "2"); prop.put("c", "3"); Properties book = new Properties(prop); book.put("A", "4"); book.put("B", "5"); System.out.println("a " + book.getProperty("a")); System.out.println("A " + book.getProperty("b")); System.out.println("c: " + book.getProperty("c")); System.out.println("z: " + book.getProperty("z", "default")); }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties prop = new Properties(); prop.put("Chapter Count", "200"); prop.put("Tutorial Count", "15"); // create a output and input as a xml file FileOutputStream fos = new FileOutputStream("properties.xml"); FileInputStream fis = new FileInputStream("properties.xml"); // store the properties in the specific xml prop.storeToXML(fos, null);//from w w w . jav a 2s . co m // load from the xml that we saved earlier prop.loadFromXML(fis); // print the properties list prop.list(System.out); }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties prop = new Properties(); prop.put("Chapter Count", "200"); prop.put("Tutorial Count", "15"); prop.put("tutorial", "java2s.com"); // create a output and input as a xml file FileOutputStream fos = new FileOutputStream("properties.xml"); FileInputStream fis = new FileInputStream("properties.xml"); // store the properties in the specific xml prop.storeToXML(fos, "Properties Example"); // print the xml while (fis.available() > 0) { System.out.print((char) fis.read()); }/* ww w . j ava 2s .co m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties props = new Properties(); props.put("mail.host", "mail.cloud9.net"); Session mailConnection = Session.getInstance(props, null); Message msg = new MimeMessage(mailConnection); Address a = new InternetAddress("a@a.com", "A a"); Address b = new InternetAddress("fake@java2s.com"); msg.setContent("Mail contect", "text/plain"); msg.setFrom(a);/* w ww. j a va2 s .co m*/ msg.setRecipient(Message.RecipientType.TO, b); msg.setSubject("subject"); Transport.send(msg); }
From source file:PropDemoDef.java
public static void main(String args[]) { Properties defList = new Properties(); defList.put("Florida", "Tallahassee"); defList.put("Wisconsin", "Madison"); Properties capitals = new Properties(defList); capitals.put("Illinois", "Springfield"); capitals.put("Missouri", "Jefferson City"); capitals.put("Washington", "Olympia"); capitals.put("California", "Sacramento"); capitals.put("Indiana", "Indianapolis"); Set states = capitals.keySet(); for (Object name : states) System.out.println(name + " / " + capitals.getProperty((String) name)); String str = capitals.getProperty("Florida"); System.out.println("The capital of Florida is " + str + "."); }
From source file:MainClass.java
public static void main(String argv[]) throws Exception { Properties props = System.getProperties(); props.put("javax.xml.transform.TransformerFactory", "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"); System.setProperties(props);/*from w w w. j a va2 s . c o m*/ TransformerFactory tFactory = TransformerFactory.newInstance(); Templates translet = tFactory.newTemplates(new StreamSource("OrderProcessing.xslt")); Transformer transformer = translet.newTransformer(); transformer.transform(new StreamSource("CustomerOrders.xml"), new StreamResult(new FileOutputStream("SortedOrders.html"))); transformer.transform(new StreamSource("CustomerOrders1.xml"), new StreamResult(new FileOutputStream("SortedOrders1.html"))); }
From source file:Main.java
public static void main(String[] args) { String from = "user@some-domain.com"; String to = "user@some-domain.com"; String subject = "Hi There..."; String text = "How are you?"; Properties properties = new Properties(); properties.put("mail.smtp.host", "smtp.some-domain.com"); properties.put("mail.smtp.port", "25"); Session session = Session.getDefaultInstance(properties, null); Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject(subject);/*from w ww . j a va2 s.com*/ message.setText(text); Transport.send(message); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Properties systemSettings = System.getProperties(); systemSettings.put("proxySet", "true"); systemSettings.put("http.proxyHost", "proxy.mycompany.local"); systemSettings.put("http.proxyPort", "80"); URL u = new URL("http://www.google.com"); HttpURLConnection con = (HttpURLConnection) u.openConnection(); BASE64Encoder encoder = new BASE64Encoder(); String encodedUserPwd = encoder.encode("domain\\username:password".getBytes()); con.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd); con.setRequestMethod("HEAD"); System.out.println(con.getResponseCode() + " : " + con.getResponseMessage()); System.out.println(con.getResponseCode() == HttpURLConnection.HTTP_OK); }
From source file:Main.java
public static void main(String[] argv) throws Exception { byte[] b = new byte[1]; Properties systemSettings = System.getProperties(); systemSettings.put("http.proxyHost", "proxy.mydomain.local"); systemSettings.put("http.proxyPort", "80"); URL u = new URL("http://www.google.com"); HttpURLConnection con = (HttpURLConnection) u.openConnection(); BASE64Encoder encoder = new BASE64Encoder(); String encodedUserPwd = encoder.encode("mydomain\\MYUSER:MYPASSWORD".getBytes()); con.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd); DataInputStream di = new DataInputStream(con.getInputStream()); while (-1 != di.read(b, 0, 1)) { System.out.print(new String(b)); }/* ww w. j a va 2s . c o m*/ }