A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© τ、高童鞋ゝ 中级黑马   /  2012-4-13 13:27  /  1410 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import javax.swing.*;
import java.io.*;
public class EditorTest extends JFrame
{
        public static void main(String[] args)
        {
                String strCommand = "dir .";
                String cmd = "cmd";
                if (!System.getProperty("os.name".equals("Windows NT")
                        cmd = "command";
                cmd = cmd + " /c " + strCommand;
                try {
                        System.out.println(System.getProperty("os.name");
                        System.out.println(cmd);
                        Runtime.getRuntime().exec(cmd);
                }catch (IOException ex) {
                        System.out.println(ex);
                }

                //System.out.println(System.getProperties().toString());
        }
}

为什么我这里运行时会有错误呢??

2 个回复

倒序浏览
System.getProperty();获取一个键的值,你怎么能用equals到里面比较内容,能不说下,你写这段程序是做什么?
回复 使用道具 举报
if(!System.getProperty("os.name".equals("Windows NT")这句代码不是一般的乱啊,System.getProperty(),它的参数、返回类型都是String类型的,而你传进去的参数是boolean型,返回的也是boolean型,好好看看API文档。。。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马