【发布时间】:2020-03-05 16:22:30
【问题描述】:
我想使用 TextIO 读取 UCS2-LE BOM 中的文件,但它似乎不起作用。 有没有办法使用这种编码的 TextIO ?或者是否有其他库可以很好地处理这种类型的编码?
我的代码是 JAVA (Apache Beam)
PCollection<KV<String, String>> csvElements =
pipeline.apply("Reads the input csv file", TextIO
.read()
.from(options.getPolledFile()))
.apply("Read File", ParDo.of(new DoFn<String, KV<String,String>>(){
@ProcessElement
public void processElement(ProcessContext c) throws UnsupportedEncodingException {
String element = c.element();
String elStr = new String(element.getBytes(),"UTF-16LE");
c.output(elStr);}}));
【问题讨论】:
-
嗨@Oumab10!请问你能分享错误信息吗?我没有发现这件事有任何限制
-
@MethkalKhalawi 我没有收到错误,但是当我打印元素时,编码不正确,我得到了奇怪的字符。
标签: java encoding google-cloud-platform google-cloud-dataflow apache-beam