File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed
out/production/exceptions-java/br/com/dio/exceptions
src/br/com/dio/exceptions Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 5
5
6
6
//Imprimir um arquivo no console.
7
7
public class CheckedException {
8
- /*public static void main(String[] args) {
9
- String nomeDoArquivo = "romances-blake-crouch.txt";
10
- imprimirArquivoNoConsole(nomeDoArquivo);
8
+ public static void main (String [] args ) {
9
+ String nomeDoArquivo = "romance-blake-crouch.txt" ;
10
+
11
+ try {
12
+ imprimirArquivoNoConsole (nomeDoArquivo );
13
+ } catch (FileNotFoundException e ) {
14
+ JOptionPane .showMessageDialog (null ,
15
+ "Revise o nome do arquivo que você deseja imprimir! " + e .getCause ());
16
+ e .printStackTrace ();
17
+ } catch (IOException e ){
18
+ //e.printStackTrace();
19
+ JOptionPane .showMessageDialog (null ,
20
+ "Ocorreu um erro inesperado! Entre em contato com o suporte! " + e .getCause ());
21
+ } finally {
22
+ System .out .println ("Chegou no finally!" );
23
+ }
11
24
12
25
System .out .println ("Apesar da exception ou não, o programa continua..." );
13
26
}
14
27
15
- public static void imprimirArquivoNoConsole(String nomeDoArquivo) {
28
+ public static void imprimirArquivoNoConsole (String nomeDoArquivo ) throws IOException {
16
29
File file = new File (nomeDoArquivo );
17
30
18
-
19
31
BufferedReader br = new BufferedReader (new FileReader (file .getName ()));
20
32
String line = br .readLine ();
21
33
@@ -28,5 +40,5 @@ public static void imprimirArquivoNoConsole(String nomeDoArquivo) {
28
40
} while (line != null );
29
41
bw .flush ();
30
42
br .close ();
31
- }*/
43
+ }
32
44
}
You can’t perform that action at this time.
0 commit comments