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 55
66//Imprimir um arquivo no console.
77public 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+ }
1124
1225 System .out .println ("Apesar da exception ou não, o programa continua..." );
1326 }
1427
15- public static void imprimirArquivoNoConsole(String nomeDoArquivo) {
28+ public static void imprimirArquivoNoConsole (String nomeDoArquivo ) throws IOException {
1629 File file = new File (nomeDoArquivo );
1730
18-
1931 BufferedReader br = new BufferedReader (new FileReader (file .getName ()));
2032 String line = br .readLine ();
2133
@@ -28,5 +40,5 @@ public static void imprimirArquivoNoConsole(String nomeDoArquivo) {
2840 } while (line != null );
2941 bw .flush ();
3042 br .close ();
31- }*/
43+ }
3244}
You can’t perform that action at this time.
0 commit comments