English 中文(简体)
阵列案文改为
原标题:Text from the array isn t being read
  • 时间:2012-05-17 22:38:13
  •  标签:
  • java

我正试图创建以下的红十字与红新月联会,然而,当守则实施时,它不会发现“001”,无论我尝试过什么,我会把它推向“JRE6”,并利用JDK6。 我用Eclipse来开发它,并利用 de子来管理它。 我用“java.exe”和“javaw.exe”两处进行了审判。 在开业时,德贝格特人显然有001人。

我的守则是:

package bot;
import java.io.*;
import java.net.*;
public class Main {
    static PrintWriter out = null;
    @SuppressWarnings("unused")
    public static void main(String[] args) {
        Socket sock = null;
        BufferedReader in = null;
        try {
            sock = new Socket("irc.jermc.co.cc",6667);
            in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
            out = new PrintWriter(sock.getOutputStream(), true);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        boolean sentconnect = false;
        while(sock.isConnected() == true){
            if(sentconnect == false){
                writeout("NICK GBot");
                writeout("USER GBot GBot GBot :GBot");
                sentconnect = true;
            }
            String data = "";
            try {
                data = in.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            data = data.trim();
            if(data != ""){
                System.out.println("[IN] " + data);
            }
            String[] ex;
            ex = data.split(" ");
            for(String debugex : ex){
                //System.out.println("DEBUGEX: " + debugex);
            }
            if(ex[1] == "001"){
                writeout("JOIN #minecraft");
            }
            try {
                Thread.sleep((long) 0.5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(ex[0] == "PING"){
                writeout("PONG " + ex[1]);
            }
        }
    }

    private static void writeout(String msg) {
        out.println(msg);
        System.out.println("[OUT] " + msg);
    }
}
最佳回答

平等必须使用String. Equals(, not

应当:

        if(! data.isEmpty()){                     // rather than: data != ""
            System.out.println("[IN] " + data);
        }
        ...
        if(ex[1].equals("001")){                  // rather than: ex[1] == "001"
            writeout("JOIN #minecraft");
        }
        ...
        if(ex[0].equals("PING")){                 // rather than: ex[0] == "PING"
            writeout("PONG " + ex[1]);
        }

See How do I compare strings in Java.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签