4 Replies Latest reply: May 7, 2012 4:52 AM by tanc08 RSS

    Which way is better to read file & close the objects ???

      Pls refer to below code:

      Method 1:

      FileInputStream fstream = new FileInputStream("textfile.txt");
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));

      or Method 2:

      BufferedReader br = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream("textfile.txt"))));

      For method 1, normally, I will cose bi, in and fstream. For method 2, I just close br. Which way is better ? For method 1, can I just close br only ?