Java 联机文本文件中的布尔值
我想在线读取文本文件,然后在文本文件的第一行中检查布尔值。我用它来检查应用程序的更新 有个主意-Java 联机文本文件中的布尔值,java,url,boolean,Java,Url,Boolean,我想在线读取文本文件,然后在文本文件的第一行中检查布尔值。我用它来检查应用程序的更新 有个主意- public static boolean needsUpdate() { URL url; boolean needs = false; try { url = new URL("https://github.com/../../blob/master/update.txt"); Scanner s = new Scanner
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=false
或update=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();
}