asked in Exception by (58.6k points)

1 Answer

public class TryWithResourseTest {
    public static void main(String[] args) throws IOException {
           InputStream inputStream = null;
           try{
                  inputStream = new FileInputStream("c:/txtFile.txt");
                  //code......
           }finally{
                  if(inputStream!=null)
                  inputStream.close();
           }
    }
}
 import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
 
/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */
public class TryWithResourseTest {
   public static void main(String[] args) throws IOException {
          try (InputStream inputStream = new FileInputStream("c:/txtFile.txt")) {
              //code...
          }
   }
}
answered by (58.6k points)

Java Interview Questions and Answers 2018

>
...