package Files;

import java.io.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

public class WriteFile {

  BufferedWriter buffer = null;

  public void WriteFile(String path, String input) throws Exception {
    try {
      File file = new File(path);
      if (!file.exists()) {
        file.createNewFile();
      }

      FileWriter fileWriter = new FileWriter(path);
      buffer = new BufferedWriter(fileWriter);
      buffer.write(input);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (buffer != null) buffer.flush();
        //                    buffer.close();
      } catch (Exception ex) {
        System.out.println("Error in closing the BufferedWriter" + ex);
      }
    }
  }
}
