title: How to write into a single file through multiple classes in Java?
body: <p>I am trying to write into a single text file through different classes.
  I opened the text file from the main class:</p>
  
  <pre><code>public static void main( String[] args ) throws Exception {
      BufferedWriter writer = new BufferedWriter(new FileWriter("src/t1.txt"));
      Parser.getParseTree().print(); // where I called the method
      writer.close();
    }
  </code></pre>
  
  <p>This is a print() method from another class:</p>
  
  <pre><code>    public static  void print() throws IOException {
  
              BufferedWriter writer = new BufferedWriter(new FileWriter("src/t1.txt"));
              writer.write("afcad fad fad");
       }
  </code></pre>
  
  <p>The <code>BufferedWriter writer = new BufferedWriter(new FileWriter("src/t1.txt"));</code>in print() method does not work and nothing prints into the <strong>t1.txt</strong>
   file.</p>