我試圖從具有try-catch塊,如何在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){}
}
在我的項目中,這對我來說是一個超級嚴重的問題。 我用Google搜索了一下,並嘗試過自己,但沒有解決。
我希望現在我會找到一些解決方案。 我知道它有錯誤,說返回語句丟失但我想程序正是這樣工作。
現在原因,我嚴格到這種
在我的jar文件我要訪問的文本文件查找值1或0,如果「1」,則激活其他禁用。
這就是爲什麼我使用布爾值。