JavaµÄ¶à½ø³ÌÔËÐÐģʽ·ÖÎö
Ò»°ãÎÒÃÇÔÚjavaÖÐÔËÐÐÆäËüÀàÖеķ½·¨Ê±£¬ÎÞÂÛÊǾ²Ì¬µ÷Ó㬻¹ÊǶ¯Ì¬µ÷Ó㬶¼ÊÇÔÚµ±Ç°µÄ½ø³ÌÖÐÖ´Ðеģ¬Ò²¾ÍÊÇ˵£¬Ö»ÓÐÒ»¸öjavaÐéÄâ»úʵÀýÔÚÔËÐС£¶øÓеÄʱºò£¬ÎÒÃÇÐèҪͨ¹ýjava´úÂëÆô¶¯¶à¸öjava×Ó½ø³Ì¡£ÕâÑù×öËäȻռÓÃÁËһЩϵͳ×ÊÔ´£¬µ«»áʹ³ÌÐò¸ü¼ÓÎȶ¨£¬ÒòΪÐÂÆô¶¯µÄ³ÌÐòÊÇÔÚ²»Í¬µÄÐéÄâ»ú½ø³ÌÖÐÔËÐеģ¬Èç¹ûÓÐÒ»¸ö½ø³Ì·¢ÉúÒì³££¬²¢²»Ó°ÏìÆäËüµÄ×Ó½ø³Ì¡£
ÔÚJavaÖÐÎÒÃÇ¿ÉÒÔʹÓÃÁ½ÖÖ·½·¨À´ÊµÏÖÕâÖÖÒªÇó¡£×î¼òµ¥µÄ·½·¨¾ÍÊÇͨ¹ýRuntimeÖеÄexec·½·¨Ö´ÐÐjava classname¡£Èç¹ûÖ´Ðгɹ¦£¬Õâ¸ö·½·¨·µ»ØÒ»¸öProcess¶ÔÏó£¬Èç¹ûÖ´ÐÐʧ°Ü£¬½«Å׳öÒ»¸öIOException´íÎó¡£ÏÂÃæÈÃÎÒÃÇÀ´¿´Ò»¸ö¼òµ¥µÄÀý×Ó¡£
// Test1.javaÎļþ
import java.io.*;
public class Test
{
public static void main(String[] args)
{
FileOutputStream fOut = new FileOutputStream("c:\\Test1.txt");
fOut.close();
System.out.println("±»µ÷Óóɹ¦!");
}
}
// Test_Exec.java
public class Test_Exec
{
public static void main(String[] args)
{
Runtime run = Runtime.getRuntime();
Process p = run.exec("java test1");
}
}
ͨ¹ýjava Test_ExecÔËÐгÌÐòºó£¬·¢ÏÖÔÚCÅ̶àÁ˸öTest1.txtÎļþ£¬µ«ÔÚ¿ØÖÆ̨Öв¢Î´³öÏÖ"±»µ÷Óóɹ¦£¡"µÄÊä³öÐÅÏ¢¡£Òò´Ë¿ÉÒԶ϶¨£¬TestÒѾ±»Ö´Ðгɹ¦£¬µ«ÒòΪijÖÖÔÒò£¬TestµÄÊä³öÐÅϢδÔÚTest_ExecµÄ¿ØÖÆ̨ÖÐÊä³ö¡£Õâ¸öÔÒòÒ²ºÜ¼òµ¥£¬ÒòΪʹÓÃexec½¨Á¢µÄÊÇTest_Exec µÄ×Ó½ø³Ì£¬Õâ¸ö×Ó½ø³Ì²¢Ã»ÓÐ×Ô¼ºµÄ¿ØÖÆ̨£¬Òò´Ë£¬Ëü²¢²»»áÊä³öÈκÎÐÅÏ¢¡£
Èç¹ûÒªÊä³ö×Ó½ø³ÌµÄÊä³öÐÅÏ¢£¬¿ÉÒÔͨ¹ýProcessÖеÄgetInputStreamµÃµ½×Ó½ø³ÌµÄÊä³öÁ÷£¨ÔÚ×Ó½ø³ÌÖÐÊä³ö£¬ÔÚ¸¸½ø³ÌÖоÍÊÇÊäÈ룩£¬È»ºó½«×Ó½ø³ÌÖеÄÊä³öÁ÷´Ó¸¸½ø³ÌµÄ¿ØÖÆ̨Êä³ö¡£¾ßÌåµÄʵÏÖ´úÂëÈçÏÂÈçʾ£º
// Test_Exec_Out.java
import java.io.*;
public class Test_Exec_Out
{
public static void main(String[] args)
{
Runtime run = Runtime.getRuntime();
Process p = run.exec("java test1");
BufferedInputStream in = new BufferedInputStream(p.getInputStream());
BufferedReader br = new BufferedReader(new&nbs
Ïà¹ØÎĵµ£º
Ò».±àд¹¹ÔìÆ÷µÄÓÐЧ׼Ôò£º Óþ¡¿ÉÄܼòµ¥µÄ·½·¨Ê¹¶ÔÏó½øÈëÕý³£×´Ì¬£¬Èç¹û¿ÉÒԵĻ°£¬±ÜÃâµ÷ÓÃÆäËû·½·¨¡£ÔÚ¹¹ÔìÆ÷ÄÚΨһÄܹ»°²È«µ÷ÓõÄÄÇЩ·½·¨ÊÇ»ùÀàÖеÄfinal·½·¨£¨Ò²ÊÊÓÃÓÚprivate·½·¨£¬ËüÃÇ×Ô¶¯ÊôÓÚfinal·½·¨£©¡£ ¶þ.Óü̳нøÐÐÉè¼ÆµÄ×¼Ôò£º Óü̳бí´ïÐÐΪ¼äµÄ²îÒ ......
ÉùÃ÷£º´ËÎÄÕÂÊÇÍøÉÏתÐ͹ýÀ´µÄ£¬·Ç±¾ÈËÖø¡£
1¡¢°´×Ö½Ú¶ÁÈ¡ÎļþÄÚÈÝ
2¡¢°´×Ö·û¶ÁÈ¡ÎļþÄÚÈÝ
3¡¢°´ÐжÁÈ¡ÎļþÄÚÈÝ
4¡¢Ëæ»ú¶ÁÈ¡ÎļþÄÚÈÝ
public class ReadfromFile {
/**
* ÒÔ×Ö½ÚΪµ¥Î»¶ÁÈ¡Îļþ£¬³£ÓÃÓÚ¶Á¶þ½øÖÆÎļþ£¬ÈçͼƬ¡¢ÉùÒô¡¢Ó°ÏñµÈÎļþ¡£
&n ......
GRASPģʽ:General Responsibility Assignment Software Patterns£ºÍ¨ÓÃÔðÈηÖÅäÈí¼þģʽ
ÀïÃæÖØÒªµÄ¸ÅÄîÊÇÔðÈΣ¬ÔðÈÎÊÇÀà¼äµÄÒ»ÖÖºÏÔ¼»òÊÇÒåÎñ£¬¿ÉÒÔϸ·ÖΪÁ½²¿·Ö£¬Óù«Ê½±íʾÈçÏ£º
ÔðÈÎ = ÖªµÀÔðÈÎ + ÐÐΪÔðÈΣ¨ÕâÀïÃæËƺõ´æÔÚ¸ÅÄîµÄÑ»·¶¨Ò壩
×¢£ºÓÃͨË׵Ļ°À´½²£¬ÔðÈξÍÊÇÒ»¸öÀàÖªµÀÒª×öʲô£¬²¢ÇÒÄܹ»×öʲô¡£
· ......
ÕâƪÎÄÕ²¢Ã»Óиø³öÈçºÎʹÓÃResultSetµÄ¾ßÌåÀý×Ó£¬Ö»ÊÇ´ÓResultSetµÄ¹¦ÄÜÐÔÉϽøÐÐÁËÏêϸµÄ½²Êö¡£Ï£ÍûÕâƪÎÄÕ¶Դó¼ÒÀí½âResultSetÄܹ»ÓÐËù°ïÖú¡£ÏÂÃæ¾ÍÊÇÕâƪÎÄÕµľßÌåÄÚÈÝ¡£
½á¹û¼¯(ResultSet)ÊÇÊý¾ÝÖвéѯ½á¹û·µ»ØµÄÒ»ÖÖ¶ÔÏ󣬿ÉÒÔ˵½á¹û¼¯ÊÇÒ»¸ö´æ´¢²éѯ½á¹ûµÄ¶ÔÏó£ ......
ÅäÖÃjava »·¾³±äÁ¿ºÜ¼òµ¥ £º
Ê×ÏÈ:
1¡¢Ë«»÷“ÎҵĵçÄÔ”
2¡¢Ë«»÷“¿ØÖÆÃæ°å”
3¡¢Ë«»÷“ϵͳ”
4¡¢µã»÷“¸ß¼¶”Ñ¡Ï£¬
5¡¢µã»÷“»·¾³±äÁ¿”°´Å¥
Æä´Î:
1¡¢±äÁ¿Ãû: path
±äÁ¿Öµ: C:\jdk1.6.0\bin;
2¡¢±äÁ¿Ãû: classpath
±äÁ¿Öµ: .;%JAVA_HOME%\lib\ ......