code: public static void writeToFile(String content, File file, Charset charset) {
          if (log.isDebugEnabled()) {
              log.debug(String.format("Writing file resource: '%s' (encoding is '%s')", file.getName(), charset.displayName()));
          }
  
          if (!file.getParentFile().exists()) {
              if (!file.getParentFile().mkdirs()) {
                  throw new CitrusRuntimeException("Unable to create folder structure for file: " + file.getPath());
              }
          }
  
          try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
              fos.write(content.getBytes(charset));
              fos.flush();
          } catch (IOException e) {
              throw new CitrusRuntimeException("Failed to write file", e);
          }
      }
docs: Writes String content to file with given charset encoding. Automatically closes file output streams when done.
  @param content
  @param file