1. 假設你使用了Apache的Commons-io包 Commons IO -
Commons IO Overview,可以使用如下程式碼:
import java.io.File
import org.apache.commons.io.FileUtils
val file = new File(filename)
content = FileUtils.readFileToString(file, "gbk")
FileUtils.write(file, content, "UTF-8")
2. 如果你用的是JAVA7:
import java.nio.file.{Paths, Files}
val content = io.Source.fromFile(filename, "gbk").mkString
Files.write(Paths.get(filename), content.getBytes("UTF8"))
1. 假設你使用了Apache的Commons-io包 Commons IO -
Commons IO Overview,可以使用如下程式碼:
import java.io.File
import org.apache.commons.io.FileUtils
val file = new File(filename)
content = FileUtils.readFileToString(file, "gbk")
FileUtils.write(file, content, "UTF-8")
2. 如果你用的是JAVA7:
import java.nio.file.{Paths, Files}
val content = io.Source.fromFile(filename, "gbk").mkString
Files.write(Paths.get(filename), content.getBytes("UTF8"))