0

I read data from file and write to destination after some transfomations.

the case :

val schema1file = Source.fromFile(s"$path", "UTF-8")
val writer = new PrintWriter(new File(s"$targetPath"))
val lines = schema1file.getLines().toArray
for (i <- 0 until lines.length) {
  val line = lines(i).toString()
    // todo
  writer.println(line)
}
writer.close

It works and save my output right.But I always find the 'FEFF' at the very beginning of the outputfile and the place I use s"$var$var1".

Could you help to tell me why and how to fix it? Thanks@

jay Wong
  • 179
  • 2
  • 12
  • 1
    Are you sure the data (which looks like a Unicode BOM that for example Windows editors like to include) is not already in the input file (and was just copied through)? https://stackoverflow.com/questions/2223882/whats-the-difference-between-utf-8-and-utf-8-without-bom – Thilo May 15 '19 at 04:30
  • 2
    Also, you don't specify a character set for the output `writer`. Better also put that to UTF-8. – Thilo May 15 '19 at 04:33
  • wow! Thanks you! I do find a feff in my source file! – jay Wong May 15 '19 at 05:12
  • 2
    Is there any function of string can check and delete these invisible characters? – jay Wong May 15 '19 at 05:13

0 Answers0