title: how to a get a specific string in a file
body: <p>here in my file content 2017-05-05 08:24:46 to 2017-05-05 08:24:55, now i need to print from-2017-05-05 08:24:49 to -2017-05-05 08:24:52 contents in between the date. can you suggest someother method other than this.</p>
  
  <p>1.file content:</p>
  
  <pre><code>[2017-05-05 08:24:46]contents is [ [pool-80 
   thread.PaseInterceptorChain... zhjkhzjh]nkshxkjghsjkgjskgxsjgxjsagxhujgsxhjsxghjvasxhasvxhjvsaxhvshjxvhjvhxjvhsvxhj
  [2017-05-05 08:24:49]contents is [ [pool-80-thread-1] xhggajgzjh
   icationExceptionOutInterceptor... nvsjhkslkxlxskl]jsahxjahx
  [2017-05-05 08:24:49]contents is [ [pool-78-thread-1.. ]
  [2017-05-05 08:24:52]contents is [ [pool-78-thread-1... ]
  [2017-05-05 08:24:52]contents is [ [pool-78-thread-1... {... = 
   contents inside}]
  [2017-05-05 08:24:55]contents is [ [pool-78-thread-1... {... = 
   contents inside}]
  </code></pre>
  
  <p>2.this is my code:</p>
  
  <pre><code>public class MeteringlogBean implements Serializable 
  {
  private static final long serialVersionUID = 1L;
  private Date date10;
  private Date date11;
  private String d;
  private String d1;
  private String s;
  private String text;
  private FileWriter fw;
  private BufferedWriter bw;
  private String Fn = "C:/Users/swetha.papireddy/Documents/new/filename.txt";
  public Date getDate11() {
  return date11;
  }
  public void setDate11(Date date11) {
  this.date11 = date11;
  }
  private String environment;
  public String getEnvironment() {
  return environment;
  }
  public void setEnvironment(String environment) {
  this.environment = environment;
  }
  public Date getDate10() {
  return date10;
  }
  public void setDate10(Date date10) {
  this.date10 = date10;
  }
  
  public void save() throws IOException, NullPointerException {
  try {
      File file = new File(getEnvironment() + "/ischange.log");
      FileReader fileReader = new FileReader(file);
      BufferedReader bufferedReader = new BufferedReader(fileReader);
      StringBuilder stringBuilder = new StringBuilder();
      String line;
      while ((line = bufferedReader.readLine()) != null) {
          stringBuilder.append(line);
          stringBuilder.append("\n");
      }
      fileReader.close();
      System.out.println("Contents of file:");
      s = stringBuilder.toString();
      System.out.println(s);
  } catch (IOException e) {
      e.printStackTrace();
  }
  
  d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date10);
  System.out.println("date:-" + d);
  d1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date11);
  System.out.println("date:-" + d1);
  
  fw = new FileWriter(Fn);
  bw = new BufferedWriter(fw);
  bw.write(s);
  bw.close();
  
  File file = new File(Fn);
  FileInputStream fis = new FileInputStream(file);
  byte[] bytes = new byte[(int) file.length()];
  fis.read(bytes);
  fis.close();
  
  String text = new String(bytes, "UTF-8");
  String str1 = new String(d);
  String str2 = new String(d1);
  System.out.println(text.substring(text.indexOf(str1),
          text.lastIndexOf(str2)));
  }
  </code></pre>
  
  <p>3.my actual output is:</p>
  
  <pre><code> [2017-05-05 08:24:49]contents is [ [pool-80-thread-1] xhggajgzjh
  icationExceptionOutInterceptor... nvsjhkslkxlxskl]jsahxjahx
  [2017-05-05 08:24:49]contents is [ [pool-78-thread-1.. ]
  [2017-05-05 08:24:52]contents is [ [pool-78-thread-1... ]
  </code></pre>
  
  <p>now i need to get two [2017-05-05 08:24:52] </p>
  
  <p>4.output should be:</p>
  
  <pre><code>[2017-05-05 08:24:49]contents is [ [pool-80-thread-1] xhggajgzjh
  icationExceptionOutInterceptor... nvsjhkslkxlxskl]jsahxjahx
  [2017-05-05 08:24:49]contents is [ [pool-78-thread-1.. ]
  [2017-05-05 08:24:52]contents is [ [pool-78-thread-1... ]
  [2017-05-05 08:24:52]contents is [ [pool-78-thread-1... {... = 
   contents inside}]
  </code></pre>