gpt4 book ai didi

java - boolean 值无法与 http 正常工作获取结果

转载 作者:行者123 更新时间:2023-12-01 19:38:17 25 4
gpt4 key购买 nike

public class networking2{

public static void main(String []args) throws IOException{
String urlLink = "http://rocktheparty5231.xtgem.com/out";
URL url = new URL(urlLink);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");

BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while((line = in.readLine()) != null) {sb.append(line);}
in.close();

// problem is here
System.out.println(sb.toString()); // sb is returning output "uc"
System.out.println(sb.toString()=="uc"); // how is this boolean false
// i am not able to do any boolean operation with this correctly please help

}

}

http 函数工作正常,但 boolean 值没有正常工作

screenshot of eclipse

最佳答案

在Java中,比较字符串时,使用.equals。请像这样尝试一下。

System.out.println(sb.toString().equals("uc"));

您可以阅读更多here

关于java - boolean 值无法与 http 正常工作获取结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56591828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com