System.out.println("Capital of Japan is " + countryCapitals.get ("Japan"));
System.out.println("Capital of France is " + countryCapitals.get("France"));
}
}
System.out.println("Capital of Japan is " + countryCapitals.get("Japan"));
System.out.println("Capital of France is " + countryCapitals.get("France"));
}
}
18. Send Email using Java
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.example.com");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress (from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress (recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
//Set the host smtp address
Properties props = new Properties();
props.put ("mail.smtp.host", "smtp.example.com");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress [recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress (recipients[i]);
}
msg.setRecipients (Message.RecipientType.TO, addressTo);
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
19. Send HTTP request & fetching data using Java
public class Main {
public static void main(String[] args) {
try {
URL my_url = new URL("http://www.viralpatel.net/blogs/");&nbs p;
BufferedReader br = new BufferedReader(new InputStreamReader
public class Main {
public static void main(String[] args) {
try {
URL my_url = new URL("http://www.viralpatel.net/blogs/");
BufferedReader br = new BufferedReader(new
/**
* Reallocates an array with a new size, and copies the contents
* of the old array to the new array.
* @param oldArray the old array, to be reallocated.
* @param newSize the new array size.
* @return A new array with the same contents.
*/
private static Object resizeArray (Object oldArray, int newSize) {
int oldSize = java.lang.reflect.Array.getLength(oldArray);
Class elementType = oldArray.getClass().getComponentType();
Object newArray = java.lang.reflect.Array.newInstance(
elementType,newSize);
int preserveLength = Math.min (oldSize,newSize);
if (preserveLength > 0)
System.arraycopy (oldArray,0,newArray,0,preserveLength);
return newArray;
}
// Test routine for resizeArray().
public static void main (String[] args) {
int[] a = {1,2,3};
a = (int[])resizeArray(a,5);
a[3] = 4;
a[4] = 5;
for (int i=0; i
System.out.println (a[i]);
}作者: renxiao2003 時(shí)間: 2010-07-12 14:32
其實(shí)樓主應(yīng)該注意你發(fā)代碼的格式,最好整齊一些,這樣方便大家看。不行你就放到code區(qū)域,這樣方便大家復(fù)制。作者: tong0245 時(shí)間: 2010-07-13 12:23
原來(lái)jdk 自帶zip有中文亂麻問(wèn)題。
用apache的就正常作者: surpass_li 時(shí)間: 2010-07-13 13:05
apache 的是什么包?作者: tong0245 時(shí)間: 2010-07-13 13:36 回復(fù) 4#surpass_li