Quantcast
Channel: GUJ - Tópicos com a tag java
Viewing all articles
Browse latest Browse all 17410

Problema com IOException?

$
0
0

@BiehNandikki escreveu:

Estava vendo aulas de Java e quando fui fazer um exemplo deu um erro, e eu tô realmente tentando entender o motivo mas não consigo.

O código:

import java.nio.file.*;
import java.io.*;
import java.nio.*;
import java.nio.charset.*;


public class AulaXTI63{
   public static void main (String[] args){
   
      Path p = Paths.get("C:/JavaEX/texto.txt");
      BufferedWriter w = null;
      Charset utf8 = StandardCharsets.UTF_8;
   
   try{
      
      w = Files.newBufferedWriter(p, utf8);
      w.write("Hello, it's me!\n");
      w.write("Hello baby");
      w.flush();
   
   
   }catch(IOException e){
      
      e.printStackTrace();
      
   }finally{
      
      if(w != null) {
         w.close();
      }
    }
  }
}

O erro:

AulaXTI63.java:29: error: unreported exception IOException; must be caught or declared to be thrown
w.close();
^
1 error

Mensagens: 4

Participantes: 2

Ler tópico completo


Viewing all articles
Browse latest Browse all 17410

Latest Images

Trending Articles

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>