file io - Cannot close my DataInputStream and DataOutputStream in java -


this question has answer here:

i have started learning file handling in java. however, in code (down below), trying close file @ end of reading , writing facing error in doing way.

package trycatch;  import java.util.scanner; import org.omg.corba.datainputstream;  import java.*; import java.io.dataoutputstream; import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.io.ioexception; import java.io.writer;  public class source {  public static void main(string[] args) throws exception {      scanner input = new scanner(system.in);     try {     file f = new file("record.txt");      fileoutputstream writing = new fileoutputstream(f);     dataoutputstream write = new dataoutputstream(writing);     write.writeutf("what things want do");      string str;      fileinputstream reading = new fileinputstream(f);     java.io.datainputstream read = new java.io.datainputstream(reading);     str = read.readutf();     system.out.println(str);     }     catch(filenotfoundexception e) {          system.out.println("the system collapsed");     }     {         write.close(); // write cannot resolved         read.close();  // read cannot resolved     }      input.close(); } } 

i trying out finally keyword can tell me why ide cannot recognize read , write when write there?

write cannot resolved

your read , write fields local try block, can't access then.initialize outside of try.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -