public class Beanutils {
public static void main(String[] args) {
Beanutils bu = new Beanutils();
bu.copyProperties();
}
public void copyProperties(){
A a = new A();
B b = new B();
b.setAge("20");
b.setName("jack");
try {
BeanUtils.copyProperties(a, b);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
System.out.println(b);
System.out.println(a);
}
}
public void testHashedMap() {
IterableMap map = new HashedMap();
map.put("a", "1");
map.put("b", new Integer(2));
MapIterator it = map.mapIterator();
while (it.hasNext()) {
Object key = it.next();
Object value = it.getValue();
System.out.println("key : " + key + ";value:" + value);
}
}
/**
*
* 得到集合里按顺序存放的key之后的某一Key
*/
public void testLinkedMap() {
OrderedMap map = new LinkedMap();
map.put("FIVE", "5");
map.put("SIX", "6");
map.put("SEVEN", "7");
System.out.println(map.firstKey()); // returns "FIVE"
System.out.println(map.nextKey("FIVE")); // returns "SIX"
System.out.println(map.nextKey("SEVEN")); // returns null
System.out.println(map.previousKey("SEVEN")); // returns "SIX"
System.out.println(map.lastKey());
}
(4) 读取property配置文件
public class Configuration {
public static void main(String[] args) {
Configuration c = new Configuration();
c.properties();
}
public void properties() {
try {
PropertiesConfiguration pc = new PropertiesConfiguration(
"E:\\projects\\commonstest\\commonstest\\src\\cn\\fulong\\configuration\\config.properties");
pc.getString("colors.background");
Integer integer = pc.getInt("window.width");
System.out.println(integer);
pc.setProperty("colors.backgroundaaa", "#000012");
pc.save();
pc.save("usergui.backup.properties");// save a copy
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
(5) 发邮件(可以添加附件)
public class EmailTest {
//用commons email发送邮件
public static void main(String args[]) throws EmailException{
//Email email = new SimpleEmail();
HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.163.com");//设置SMTP服务器
email.setAuthenticator(new DefaultAuthenticator("javaemailtest", "fulong"));
email.setFrom("javaemailtest@163.com");
email.setSubject("TestMail");
//email.setMsg("This is a test mail ... :-)");
email.setHtmlMsg("<b>msg中文</b>");
email.addTo("490791132@qq.com");
File file = new File("E:\\projects\\commonstest\\commonstest\\src\\cn\\fulong\\configuration\\config.properties");
email.attach(file);
email.send();
}
}