Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java .等于不使用扫描仪_Java_Minecraft_Bukkit - Fatal编程技术网

Java .等于不使用扫描仪

Java .等于不使用扫描仪,java,minecraft,bukkit,Java,Minecraft,Bukkit,我知道它正在读取文件,因为我让它将txt文件的内容打印到控制台,但每次我尝试。等于变量没有变为true/false只是保持为true有什么想法吗 public static void readWebPage() { URLConnection connection; try { connection = new URL("https://dl.dropbox.com/u/40562795/List.txt").openConnection();

我知道它正在读取文件,因为我让它将txt文件的内容打印到控制台,但每次我尝试。等于变量没有变为true/false只是保持为true有什么想法吗

public static void readWebPage() {
      URLConnection connection;
      try {
       connection = new URL("https://dl.dropbox.com/u/40562795/List.txt").openConnection();
       @SuppressWarnings("resource")
       Scanner scanner = new Scanner(connection.getInputStream());
       scanner.useDelimiter("\\z");
       String text = scanner.next();
        System.out.println(text);
        if(text.equals("stop")){
            stop = true;
            System.out.println("Successfully stopped.");
        }else{ if(text.equals("-"))
            stop = false;
            System.out.println("Successfully started.");
        }
      } catch (MalformedURLException e) {
       e.printStackTrace();
      } catch (IOException e) {
       e.printStackTrace();
      }
 }
编辑:

它现在可以读取了,但是我的变量没有更新为true/false。它保持为true,或者在控制台中这样说

if(stop = false){
    System.out.println("stop = false.");
}else
if(stop = true){
    System.out.println("stop = true.");
}
我的变量是如何生成的:

 public static boolean stop = false;

这就是我创建变量的方式,它应该=false,但停止或更改它。我在java文件中搜索了一些可能触发它为true的内容,但没有找到任何内容。

远程文本文件中的
-
字符后面有一个尾随空格。您可以使用空白分隔符而不是行终止符分隔符。替换

scanner.useDelimiter("\\z");

这样您的
文本
将匹配您的
.equals
检查

编辑:

在编辑中,您的
if
语句表达式中有一个赋值:

if (stop = false) {
取代

if (stop == false) {
或者更好

if (!stop) {
总的来说,如果不需要这个
语句,您只需编写

System.out.println("stop = " + stop);

输入中可能有空格或\n。
System.out.println("stop = " + stop);