当我使用 NetBeans 6.8 和 Eclipse 运行此代码时,为什么输出会有所不同?

Why do the outputs differ when I run this code using NetBeans 6.8 and Eclipse?(当我使用 NetBeans 6.8 和 Eclipse 运行此代码时,为什么输出会有所不同?)

本文介绍了当我使用 NetBeans 6.8 和 Eclipse 运行此代码时,为什么输出会有所不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 Eclipse 和 NetBeans 6.8 运行以下代码时.我想查看计算机上可用的 COM 端口.在 Eclipse 中运行时,它会返回所有可用的 COM 端口,但在 NetBeans 中运行时,它似乎没有找到任何端口..

When I am running the following code using Eclipse and NetBeans 6.8. I want to see the available COM ports on my computer. When running in Eclipse it is returning me all available COM ports but when running it in NetBeans, it does not seem to find any ports ..

public static void test(){
    Enumeration lists=CommPortIdentifier.getPortIdentifiers();

    System.out.println(lists.hasMoreElements());
    while (lists.hasMoreElements()) {
        CommPortIdentifier cn=(CommPortIdentifier)lists.nextElement();

        if ((CommPortIdentifier.PORT_SERIAL==cn.getPortType())) {
            System.out.println(
              "Name is serail portzzzz " +
              cn.getName() +
              " Owned status " +
              cn.isCurrentlyOwned());

            try{
                SerialPort port1=(SerialPort)cn.open("ComControl",800000);
                port1.setSerialPortParams(
                  9600,
                  SerialPort.DATABITS_8,
                  SerialPort.STOPBITS_1,
                  SerialPort.PARITY_NONE);
                System.out.println("Before get stream");
                OutputStream out=port1.getOutputStream();
                InputStream input=port1.getInputStream();
                System.out.println("Before write");
                out.write("AT".getBytes());
                System.out.println("After write");
                int sample=0;
                //while((( sample=input.read())!=-1)){
                System.out.println("Before read");
                //System.out.println(input.read() + "TEsting ");
                /

本文标题为:当我使用 NetBeans 6.8 和 Eclipse 运行此代码时,为什么输出会有所不同?

基础教程推荐