title: FileWriter not writing?
body: <p>I have this snippet of code:</p>
  
  <pre><code>        try {
              f1 = new File("sink.txt");
              f1.createNewFile();
              fw = new FileWriter(f1);
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
          ... code ...
          System.out.println(sequence);
          System.out.println(mySink.indexOf(sequence));
          String result = "";
          int firstIndex = mySink.indexOf(sequence);
          if (firstIndex &gt;= 0) {
              System.out.println(true);
              int secondIndex = mySink.indexOf(sequence, firstIndex + sequence.length());
              if (secondIndex &gt;= 0) {
                  System.out.println(true);
                  result = mySink.substring(firstIndex, secondIndex + sequence.length());
                  System.out.println(result);
              }
          }
          try { // Write it to file
              fw.write(result);
          } catch (IOException e) {
              e.printStackTrace();
          } 
          System.out.println("done");
  </code></pre>
  
  <p>When I ranit, it printed the string <code>sequence</code> and the index of it inside <code>mySink</code>. Then it goes inside the if statements and printed out the two <code>true</code> and printed out <code>result</code> so I know <code>result</code> was initialized successfully. But when I look into the file <code>sink.txt</code>, I see that it's blank. Why is it behaving this way? Did I miss something in my code? It was working before and I added some more code and it does this. I never touch the <code>FileWriter</code> or the <code>File</code> during the execution of the program. Thanks in advance! </p>
  
  <p>This is my output if you want to see:</p>
  
  <pre><code>[93, 73, 74, 81, 89, 70, 50, 80, 51, 83, 62, 13, 50, 0, 40, 98, 48, 43, 47, 89]
  2000466
  true
  true
  [93, 73, 74, 81, 89, 70, 50, 80, 51, 83, 62, 13, 50, 0, 40, 98, 48, 43, 47, 89]
  [93, 73, 74, 81, 89, 70, 50, 80, 51, 83, 62, 13, 50, 0, 40, 59, 48, 43, 47, 89]
  [93, 73, 74, 81, 89, 70, 50, 80, 51, 83, 62, 13, 50, 0, 81, 59, 48, 43, 47, 89]
  [93, 73, 74, 81, 89, 70, 50, 80, 51, 83, 62, 13, 50, 0, 81, 98, 48, 43, 47, 89]
  [93, 73, 74, 81, 89, 70, 50, 80, 51, 83, 62, 13, 50, 0, 40, 98, 48, 43, 47, 89]
  done
  </code></pre>