Javaµ÷ÓÃLinuxÃüÁî
Java¿ÉÒÔÖ±½Óµ÷ÓÃLinuxÃüÁÐÎʽÈçÏ£º
Runtime.getRuntime().exec(command)
¾ÙÀý£ºÔËÐÐls,topÃüÁî¿ÉÒÔÕâÑù£º
Runtime.getRuntime().exec("ls");
µ«ÊÇÕâÑùÖ´ÐÐʱûÓÐÈκÎÊä³ö£¬ÔÒò£º
µ÷ÓÃRuntime.exec·½·¨½«²úÉúÒ»¸ö±¾µØµÄ½ø³Ì,²¢·µ»ØÒ»¸öProcess×ÓÀàµÄʵÀý£¬
£¨×¢Ò⣺Runtime.getRuntime().exec£¨command£©·µ»ØµÄÊÇÒ»¸öProcessÀàµÄʵÀý£©,
¸ÃʵÀý¿ÉÓÃÓÚ¿ØÖƽø³Ì»òÈ¡µÃ½ø³ÌµÄÏà¹ØÐÅÏ¢. ÓÉÓÚµ÷ÓÃRuntime.exec·½·¨Ëù´´½¨µÄ×Ó½ø³ÌûÓÐ×Ô¼ºµÄÖն˻ò¿ØÖÆ̨,Òò´Ë¸Ã×Ó½ø³ÌµÄ±ê×¼IO(Èçstdin,stdou,stderr)¶¼Í¨¹ýProcess.getOutputStream(),Process.getInputStream(), Process.getErrorStream()·½·¨Öض¨Ïò¸øËüµÄ¸¸½ø³ÌÁË.Óû§ÐèÒªÓÃÕâЩstreamÀ´Ïò×Ó½ø³ÌÊäÈëÊý¾Ý»ò»ñÈ¡×Ó½ø³ÌµÄÊä³ö. ¿ÉÒÔ²ÉÓÃÈçÏ·½·¨£º
public static void main(String[] agrs){
try
{
Process process = Runtime.getRuntime().exec ("ls");
InputStreamReader ir=newInputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader (ir);
String line;
while ((line = input.readLine ()) != null){
System.out.println(line)
}
}catch (java.io.IOException e){
System.err.println ("IOException " + e.getMessage());
}
}
Ïà¹ØÎĵµ£º
public class OuterClass
{
public class InnerClass
{
public int code = 100;
}
public static void main(String[] args)
{
OuterClass outer = new OuterClass();
OuterClass.InnerClass o = outer.new InnerClass();
System. ......
±¾ÆªÎÄÕÂÀ´Ô´ÓÚ£º¿ª·¢Ñ§Ôº http://edu.codepub.com ÔÎÄÁ´½Ó£ºhttp://edu.codepub.com/2010/0221/20469.php
½Ó¿ÚÉêÃ÷±ØÐëÓÐinterface¹Ø¼ü×ֺͽӿڵÄÃû×Ö£¬publicÖ¸Ã÷ÈÎÒâÀà¾ù¿ÉÒÔʹÓÃÕâ¸ö½Ó¿Ú£¬Ä¬ÈÏÇé¿öÏ£¬Ö»ÓÐÓë¸Ã½Ó¿Ú¶¨ÒåÔÚͬһ¸ö°üÖеÄÀà²Å¿ÉÒÔ·ÃÎÊÕâ¸ö½Ó¿Ú¡£extends ÓëÀà ......
Ê×ÏȽéÉÜһϻ·¾³±äÁ¿µÄÉèÖ÷½·¨£º
£¨ÕâÀïÒÔjdk1.5À´°²×°£¬ÆäËû°æ±¾Ò»Ñù£©
ÔÚ°Ñjdk1.5°²×°µ½¼ÆËã»úÖÐÖ®ºó£¬ÎÒÃÇÀ´½øÐÐÉèÖÃʹjava»·¾³Äܹ»Ê¹Óá£
Ê×ÏÈÓÒ¼üµãÎҵĵçÄÔ¡£´ò¿ªÊôÐÔ¡£È»ºóÑ¡Ôñ“¸ß¼¶”ÀïÃæµÄ“»·¾³±äÁ¿”£¬ÔÚеĴò¿ª½çÃæÖеÄϵͳ±äÁ¿Ð ......
[------------------------------------------------------------------------]
[-- Uninformed Research -- informative information for the uninformed. --]
[------------------------------------------------------------------------]
[-- Genre : Development ......