标题:readUTF()
只看楼主
rohalloway
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:97
专家分:405
注 册:2018-9-28
结帖率:75%
 问题点数:0 回复次数:1 
readUTF()
程序代码:
try {
            DataInputStream dis = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
            DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));

            boolean offon = true;
            
            do 
            {

                String reviMsg = dis.readUTF();
                System.out.println("从客户端" + clientNo + "接收到的数据为:" + reviMsg);
                
                if(reviMsg == "end") {
                    System.out.println("offon = false;");
                    offon = false;
                }
            } 
            while (offset);
        } 



请问,当我在客户端发送 end 时,为什么不能结束循环呢?

打印的reviMsg 明明就是end,谢谢!

我想实现:当检测到客户端发来的数据为end时停止循环
搜索更多相关主题的帖子: 数据 客户端 new end 循环 
2020-03-30 21:49
rohalloway
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:97
专家分:405
注 册:2018-9-28
得分:0 
已解决

问题出现在if(reviMsg == "end")

Java中的字符串“内容”比较应使用 reviMsg.equalsIgnoreCase("end")
2020-03-30 22:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-500744-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.818634 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved