1、switch語句中可以使用字符串
switch(week){
case:"Monday"
break;
}
2、處理不同的異常
try {
File file = new File("");
FileInputStream inputStream = new FileInputStream(file);
SimpleDateFormat format = new SimpleDateFormat();
format.parse("");
} catch (FileNotFoundException|ParseException e) {
e.printStackTrace();
}
3、try-with-resources(TWR),資源自動化管理,不用再手動去關閉資源。
File file = new File("");
try(FileInputStream inputStream = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(inputStream)) {
System.out.println(inputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}