【发布时间】:2013-02-08 10:34:02
【问题描述】:
我正在尝试从具有 try-catch 块的函数中返回一个布尔值,
但问题是我无法返回任何值。
我知道 try-catch 块中的变量无法在其外部访问,但我仍然想访问。
public boolean checkStatus(){
try{
InputStream fstream = MyRegDb.class.getClassLoader().getResourceAsStream("textfile.txt");
// Use DataInputStream to read binary NOT text.
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
strLine = br.readLine();
// Print the content on the console
System.out.println (strLine);
ind.close();
if(strLine.equals("1")){
return false;
}else{
return true;
}
}catch(Exception e){}
}
在我的项目中,这对我来说是一个非常严重的问题。 我用谷歌搜索,并尝试了自己,但没有解决。
我希望现在我能找到一些解决方案。 我知道它有错误说 return statement missing,但我希望程序完全像这样工作。
现在我对此很严格的原因
在我的 jar 文件中,我必须访问文本文件以查找值 1 或 0,如果“1”则激活,否则停用。
这就是我使用布尔值的原因。
【问题讨论】:
标签: java return try-catch return-value