BufferedReader를 사용하고 있으며 close() 메서드를 호출해도 Eclipse는 여전히 경고 메시지를 표시합니다. 잠시 전에 close() 호출을하면 Eclipse에서 경고를 표시하지 않지만 코드가 작동하지 않습니다. 내 코드에 오류가 있습니까? 아니면 다른 문제가 있습니까? 코드 :BufferedReader가 닫히지 않았습니다. 경고가 사라지지 않습니다.
이Hashtable<String, Hashtable<String, Integer>> buildingStats = new Hashtable<String, Hashtable<String, Integer>>();
try
{
BufferedReader br = new BufferedReader(new FileReader(new File("Assets/Setup/Buildings.txt"))); // Sets the buildings values to the values in Buildings.tx
String line;
int lineNum = 0;
while((line = br.readLine()) != null)
{
++lineNum;
String[] values = line.split(",");
if (values.length != 3)
throw new Exception("Invalid data in Assets/Setup/Buildings.txt at line " + lineNum);
if (buildingStats.containsKey(values[0]))
{
buildingStats.get(values[0]).put(values[1], Integer.parseInt(values[2]));
}
else
{
buildingStats.put(values[0], new Hashtable<String, Integer>());
buildingStats.get(values[0]).put(values[1], Integer.parseInt(values[2]));
}
}
br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
return buildingStats;
퍼팅 시도 br.close(); 'finally'블록에서 – redFIVE
마침내 닫아야합니다. 그 행에 도달하기 전에 예외가 발생하면 어떻게 될까요? –