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
Ïà¹ØÎĵµ£º
Ò».ÏîÄ¿¼ò½é£º
¡¡¡¡JAVAÓïÑÔÊÇÒ»ÖÖ¿ÉÒÆÖ²µÄ£¬¼òµ¥µÄ£¬½¡×³µÄǶÈëʽÓïÑÔ¡£²¢ÇÒ¶ÔÍøÂ磬Êý¾Ý¿âÓкܺõÄÖ§³Ö£¬»ùÓÚJAVAÓïÑÔµÄÕâÖÖÌØÐÔ¿ÉÒÔÊ®·ÖÈÝÒ׵ؽ¨Á¢Ò»¸öСÐÍINTERNET·þÎñÆ÷¡£
¡¡¡¡±¾ÏîÄ¿ÖУ¬×÷ÕßÓÃJAVAÓïÑÔ±àдÁËÒ»¸öWEB΢ÐÍ·þÎñÆ÷£¬¶Ô¼òµ¥µÄHTTPÇëÇó½øÐÐÏìÓ¦£¬²¢Í¨¹ýºó¶ËÊý¾Ý¿â¶ÔÓû§µÄ²éѯ½øÐд¦Àí£¬´Ó¶ø¶¯Ì¬µØ·µ»ØHT ......
ÎÒ»Ò³£¼¦¶³£¬ACÁËÒ»¸ö188ÈËACµÄÌâÄ¿£¬¿ªÊ¼ËÀ»îRE£¬ÈÃÈ˲»½ûÄԲУ¬ÀíÂÛÉÏ°´ÌâÄ¿ÃèÊö½ÓÊÕsplitµÄstringÊý×鿪µ½2×ã×ã¹»£¬µ«ÊÇHH´óÅ£»¹ÊÇÖ´×ŵÄÌá³öÁËÊý×éÔ½½çµÄ¿ÉÄÜ£¬ºóÀ´¿´ÄǸö´óСΪ5µÄÊý×éÓеãÌ«¸ðÀĘ̂£¬Ë÷ÐԸijÉ105(¿ÉÊÇÃ÷Ã÷2¸ö¾Í¹»ÁË°¡£¬°¡£¬°¡£¬°¡£¬f**k)£¬È»ºó½»£ºAC£¬¿¿¡£ÄÔ²Ð+1£¬Ôôô¿ÉÄÜÄØ£¡ÄѵÀÌâÄ¿ÃèÊöÓÖÔÚÍæÈË£¬ ......
ºÜ¶àÅóÓÑÔÚÉîÈëµÄ½Ó´¥JavaÓïÑÔºó¾Í»á·¢ÏÖÕâÑùÁ½¸ö´Ê£º·´ÉäºÍÄÚÊ¡£¬Ö®Ç°ÎÒÃÇÒѾͨ¹ýʵÀý½âÎöÁËJavaµÄ·´Éä»úÖÆ£¬ÔÚʲô³¡ºÏÏÂÓ¦ÓÃÒÔ¼°ÈçºÎʹÓ㿽ñÌì°ÑÕâ¶þÕß·ÅÔÚÒ»Æð½éÉÜ£¬ÒòΪËüÃǶþÕßÊÇÏศÏà³ÉµÄ¡£
·´Éä
Ïà¶Ô¶øÑÔ£¬·´Éä±ÈÄÚÊ¡¸üÈÝÒ×Àí½âÒ»µã¡£ÓÃÒ»¾ä±È½Ï°×µÄ»°À´¸ÅÀ¨£¬·´Éä¾ÍÊÇÈÃÄã¿ÉÒÔͨ¹ýÃû³ÆÀ´µÃµ½¶ÔÏó(À࣬ÊôÐÔ£ ......
ÕâƪÎÄÕ²¢Ã»Óиø³öÈçºÎʹÓÃResultSetµÄ¾ßÌåÀý×Ó£¬Ö»ÊÇ´ÓResultSetµÄ¹¦ÄÜÐÔÉϽøÐÐÁËÏêϸµÄ½²Êö¡£Ï£ÍûÕâƪÎÄÕ¶Դó¼ÒÀí½âResultSetÄܹ»ÓÐËù°ïÖú¡£ÏÂÃæ¾ÍÊÇÕâƪÎÄÕµľßÌåÄÚÈÝ¡£
½á¹û¼¯(ResultSet)ÊÇÊý¾ÝÖвéѯ½á¹û·µ»ØµÄÒ»ÖÖ¶ÔÏ󣬿ÉÒÔ˵½á¹û¼¯ÊÇÒ»¸ö´æ´¢²éѯ½á¹ûµÄ¶ÔÏó£ ......
ÅäÖÃjava »·¾³±äÁ¿ºÜ¼òµ¥ £º
Ê×ÏÈ:
1¡¢Ë«»÷“ÎҵĵçÄÔ”
2¡¢Ë«»÷“¿ØÖÆÃæ°å”
3¡¢Ë«»÷“ϵͳ”
4¡¢µã»÷“¸ß¼¶”Ñ¡Ï£¬
5¡¢µã»÷“»·¾³±äÁ¿”°´Å¥
Æä´Î:
1¡¢±äÁ¿Ãû: path
±äÁ¿Öµ: C:\jdk1.6.0\bin;
2¡¢±äÁ¿Ãû: classpath
±äÁ¿Öµ: .;%JAVA_HOME%\lib\ ......