Source.fromFile(fileName)(enc: Encode),如果遇到错误: java.nio.charset.MalformedInputException: Input length = 1 at java.nio.charset.CoderResult.throwException(CoderResult.java:277) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:337) at sun.nio.cs.…
二进制读取文件: val file = new File("F:\\scalaWorkspace\\ScalaLearning\\files\\test.txt") val in = new FileInputStream(file) val bytes = new Array[Byte](file.length().toInt) in.read(bytes) in.close() 写文件: val out = new PrintWriter("F:\\scalaWorksp…
解决 python 读取文件乱码问题(UnicodeDecodeError) 确定你的文件的编码,下面的代码将以'utf-8'为例,否则会忽略编码错误导致输出乱码 解决方案一 with open(r'/Users/mac/Desktop/face/2.1.docx', 'rb', ) as fr: data = fr.read() line_list = data.decode('utf8').split('\n') data_l = [] for line in line_list: line…