title: Trying to UTF-8 encode the Files.write(..) but getting a OutOfMemoryError
body: <p>I'm trying to encode my text file with UTF-8. When I do this, it works.</p>
  
  <pre><code>protected void writeFile(Path dir, StringBuilder sb) {
      try {
          String fileName = dir.toFile().getAbsolutePath() + File.separator + getClass().getSimpleName().toLowerCase() + ".impex";
          Path path = Paths.get(fileName);
          Files.write(path, sb.toString().getBytes(), StandardOpenOption.CREATE);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>But when I use the encoding UTF-8 or UTF8 than I get a java.lang.OutOfMemoryError: Java heap space. Why is that and how can I solve this issue? (My memory settings are already 2GB)</p>
  
  <pre><code>protected void writeFile(Path dir, StringBuilder sb) {
      try {
          String fileName = dir.toFile().getAbsolutePath() + File.separator + getClass().getSimpleName().toLowerCase() + ".impex";
          Path path = Paths.get(fileName);
          Files.write(path, sb.toString().getBytes("UTF8"), StandardOpenOption.CREATE);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>