File tree Expand file tree Collapse file tree 3 files changed +15
-6
lines changed
out/production/exceptions-java/br/com/dio/exceptions
src/br/com/dio/exceptions Expand file tree Collapse file tree 3 files changed +15
-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 = JOptionPane.showInputDialog("Nome do arquivo a ser exibido: ");
10- imprimirArquivoNoConsole(nomeDoArquivo);
8+ public static void main (String [] args ) {
9+ String nomeDoArquivo = "romances-blake-crouch.txt" ;
10+ try {
11+ imprimirArquivoNoConsole (nomeDoArquivo );
12+ } catch (FileNotFoundException exception ){
13+ JOptionPane .showMessageDialog (null ,"O arquivo não existe!" );
14+ exception .printStackTrace ();
15+ } catch (IOException e ) {
16+ JOptionPane .showMessageDialog (null ,"Ocorreu um erro não esperado!" );
17+ e .printStackTrace ();
18+ }
1119
1220 System .out .println ("Apesar da exception ou não, o programa continua..." );
1321 }
1422
15- public static void imprimirArquivoNoConsole(String nomeDoArquivo) {
23+ public static void imprimirArquivoNoConsole (String nomeDoArquivo ) throws IOException {
1624 File file = new File (nomeDoArquivo );
1725
26+
1827 BufferedReader br = new BufferedReader (new FileReader (file .getName ()));
1928 String line = br .readLine ();
2029
@@ -27,5 +36,5 @@ public static void imprimirArquivoNoConsole(String nomeDoArquivo) {
2736 } while (line != null );
2837 bw .flush ();
2938 br .close ();
30- }*/
39+ }
3140}
Original file line number Diff line number Diff line change 66public class ExceptionCustomizada_1 {
77 public static void main (String [] args ) {
88
9- String nomeDoArquivo = JOptionPane . showInputDialog ( "Nome do arquivo a ser exibido: " ) ;
9+ String nomeDoArquivo = "romances-blake-crouch.txt" ;
1010 imprimeArquivoNoConsole (nomeDoArquivo );
1111 System .out .println ("Vai chegar nessa linha independente de qualquer coisa!" );
1212 }
You can’t perform that action at this time.
0 commit comments