1 2 3 4 Previous Next 53 Replies Latest reply: Jul 30, 2008 9:05 AM by 843785 RSS

    Reading text from file and storing

    843785
      Dear all,


      I would like to read from a text file and store the contents which from the file which would be used later.Currently i am able to read from a file but i am not able to store the contents temporarily.Can someone show how it is done?

      My codes:
      try {
              BufferedReader in = new BufferedReader(new FileReader("infilename"));
              String str;
              while ((str = in.readLine()) != null) 
              {
                  System.out.println(str);
              }
              in.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
      System.out.println(str);
      i want to store the temporarily but after the file is close, the contents are lost.The last line prints out null for str variable.Please help
        1 2 3 4 Previous Next