我想在线阅读文本文件,然后在文本文件的第一行中检查布尔值。我正在用它来检查应用程序的更新。

这是个主意-

    public static boolean needsUpdate()
{
    URL url;
    boolean needs = false;
    try
    {
        url = new URL("https://github.com/../../blob/master/update.txt");
        Scanner s = new Scanner(url.openStream());

        boolean getUpdate = s.hasNextBoolean();

        if (getUpdate = true)
        {
            needs = true;
        }
        else
        {
            needs = false;
        }
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    return needs;
}


文件中的文本为update = falseupdate = true

最佳答案

那样做:

try {
    URL url = new URL("https://github.com/../../blob/master/update.txt");
    Scanner s = new Scanner(url.openStream());
    String text = s.nextLine();
    s.close();
    text = text.replaceAll("update = ", "");
    Boolean getUpdate = Boolean.parseBoolean(text);
    //do something with the boolean
} catch(Exception ex) {
    ex.printStackTrace();
}

关于java - 在线文本文件中的 boolean 值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30920592/

10-13 09:07