Java method Exception throw with return instance.
![知识共享许可协议](http://i.creativecommons.org/l/by/3.0/80x15.png)
Work by Jianfei is licensed under a Creative Commons wei 3.0 Unported License.
1. We will get an error if write the getInstance method like below, cause the StaticEnvLib() throw a exception but there is no try- catch to catch it during the return new method.
public static StaticEnvLib getInstance()
{
return new StaticEnvLib();
}
public StaticEnvLib() throws IOException {
String filename = "H:\\Darwin.ini";
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(filename), "UTF-8"));
read(reader);
reader.close();
}
2. Modify the StaticEnvLib to like below.
public StaticEnvLib() {
String filename = "H:\\Darwin.ini";
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(filename), "UTF-8"));
read(reader);
reader.close();
}
![知识共享许可协议](http://i.creativecommons.org/l/by/3.0/80x15.png)
Work by Jianfei is licensed under a Creative Commons wei 3.0 Unported License.
- Make people around you successful is the biggest contribution to ourselves. -