Skip to content

Commit

Permalink
by default write files in UTF-8 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
neowit committed May 13, 2015
1 parent 42f121b commit c4b2219
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/scala/com/neowit/utils/FileUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ object FileUtils {
crc.getValue
}

def writeFile(text: String, file: File, append: Boolean = false) = {
val writer = new FileWriter(file, append)
def writeFile(text: String, file: File, append: Boolean = false, codec: scala.io.Codec = UTF_8) = {
val writer = new FileWriterWithEncoding(file, append, codec)
try{
writer.write(text)
} finally{
Expand All @@ -239,3 +239,6 @@ object FileUtils {
scala.io.Source.fromFile(path)(UTF_8)
}
}

private class FileWriterWithEncoding(file: File, append: Boolean, codec: scala.io.Codec)
extends OutputStreamWriter(new FileOutputStream(file, append), codec.charSet)

0 comments on commit c4b2219

Please sign in to comment.