1. public void autoCatch()
2. {
3. try {
4. FileInputStream fis = null ;
5. byte[] bArr = new byte[1024] ;
6. //會拋出FileNotFoundException
7. fis = new FileInputStream("D:/1.txt") ;
8. //會拋出IOException
9. fis.read(bArr) ;
10. }
11. catch(Exception ex) {
12. }
13. }
1. public void autoCatch()
2. {
3. FileInputStream fis = null ;
4. byte[] bArr = new byte[1024] ;
5. try {
6. //會拋出FileNotFoundException
7. fis = new FileInputStream("D://1.txt") ;
8. //會拋出IOException
9. fis.read(bArr) ;
10. }
11. catch(FileNotFoundException ex) {
12. System.out.println("D://1.txt文件不存在,請檢查") ;
13. }
14. catch(IOException ex) {
15. System.out.println("D://1.txt文件讀寫發生異常,異常信息為:" +
16. ex.getMessage()) ;
17. }
18. finally {
19. if(fis != null) {
20. try {
21. fis.close() ;
22. }
23. catch(IOException ex1) {
24. System.out.println("關閉文件輸入流的時候發生異常,異常信息為:
25. " + ex1.getMessage()) ;
26. }
27. }
28. }
29. }
1. public void autoCatch()
2. {
3. FileInputStream fis = null ;
4. byte[] bArr = new byte[1024] ;
5. try {
6. //會拋出FileNotFoundException
7. fis = new FileInputStream("D://1.txt") ;
8. //會拋出IOException
9. fis.read(bArr) ;
10. }
11. catch(FileNotFoundException ex) {
12. }
13. catch(IOException ex) {
14. }
15. }
進入討論組討論。
新聞熱點
疑難解答