diff --git a/compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala b/compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala index 9c85d2f5bd1d..96e88e5c68ae 100644 --- a/compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala +++ b/compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala @@ -8,6 +8,9 @@ import collection.mutable import scala.annotation.tailrec import dotty.tools.dotc.reporting.Reporter +import java.io.OutputStreamWriter +import java.nio.charset.StandardCharsets.UTF_8 + /** Handles rewriting of Scala2 files to Dotty */ object Rewrites { private class PatchedFiles extends mutable.HashMap[SourceFile, Patches] @@ -54,13 +57,11 @@ object Rewrites { ds } - def writeBack(): Unit = { + def writeBack(): Unit = val chars = apply(source.underlying.content) - val bytes = new String(chars).getBytes - val out = source.file.output - out.write(bytes) - out.close() - } + val osw = OutputStreamWriter(source.file.output, UTF_8) + try osw.write(chars, 0, chars.length) + finally osw.close() } /** If -rewrite is set, record a patch that replaces the range