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. }
进入讨论组讨论。
新闻热点
疑难解答