import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CommandLine {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Begin...");
try {
Runtime rt = Runtime.getRuntime();
String[] cmd = {"cmd.exe" , "/c" , "start","notepad"};
System.out.println(cmd.length);
Process p = rt.exec(cmd);
BufferedReader in = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Final");
}
}
Tuesday, December 23, 2008
Chạy chương trình với Runtime.getRuntime().exec()
Posted by Hoang Le Thanh at 2:12 AM 0 comments
Labels: Java Story
Monday, December 22, 2008
Gởi mail với JavaMail
Lâu rùi chạy lại chương trình gởi mail qua tài khoản Gmail cũng vui :)
Chương trình : Download
Tham khảo chi tiết: http://java.sun.com/products/javamail/
Các bạn muốn chạy chỉ cần load chương trình về, sửa các thông tin sau thì chạy được:
account: account gmail
password: password gmail
subject: Chủ đề mail
sender: Người gởi
recipients: Người nhận
Bạn có thể chỉnh sửa để chạy với những mail server khác nhau.
Để tối ưu khi chạy, có thể xem thêm gởi mail bằng daemon thread, mục đích không làm dump bộ nhớ khi gởi mail.
Để chạy được chương trình cần hai gói thư viện, có đính kèm theo hoặc download ở Java mail và JavaBeans Activation Framework
Posted by mabuitvn at 12:30 AM 0 comments
Labels: Java Story