Java 在FSDataOutputStream(Hadoop)中以UTF-8编码写入文件?

Java 在FSDataOutputStream(Hadoop)中以UTF-8编码写入文件?,java,csv,utf-8,mapreduce,cartodb,Java,Csv,Utf 8,Mapreduce,Cartodb,我正在尝试将csv写入MapReduce的reducer函数中的文件。这是我的密码: public class DataSet311Reducer extends Reducer<Text, Text, Text, Text> { @Override public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedE

我正在尝试将csv写入MapReduce的reducer函数中的文件。这是我的密码:

public class DataSet311Reducer extends Reducer<Text, Text, Text, Text> {

  @Override
  public void reduce(Text key, Iterable<Text> values, Context context)
      throws IOException, InterruptedException {
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(conf);
    Path path = new Path(key.toString().toLowerCase() + ".csv");
    FSDataOutputStream os = fs.create(path);
    os.writeChars("KEY,DATE,AGENCY,DESCRIPTOR,LOCATIONTYPE,INCIDENTZIP,INCIDENTADDRESS,LATITUDE,LONGITUDE\n");
    StringBuilder sb = new StringBuilder();
    for (Text value : values) {
      sb.append(value.toString());
      sb.append("|");
      os.writeUTF(value.toString());
      os.writeUTF("\n");
    }
    os.close();
    context.write(key, new Text(sb.toString()));
  }
}
公共类数据集311reducer扩展{
@凌驾
公共void reduce(文本键、Iterable值、上下文)
抛出IOException、InterruptedException{
Configuration conf=新配置();
FileSystem fs=FileSystem.get(conf);
路径路径=新路径(key.toString().toLowerCase()+“.csv”);
FSDataOutputStream os=fs.create(路径);
os.writeChars(“键、日期、代理、描述符、位置类型、INCIDENTZIP、INCIDENTADDRESS、纬度、经度\n”);
StringBuilder sb=新的StringBuilder();
用于(文本值:值){
sb.append(value.toString());
某人加上(“|”);
writeUTF(value.toString());
os.writeUTF(“\n”);
}
os.close();
编写(键,新文本(sb.toString());
}
}
我需要将文件存储为UTF-8编码,以便与CartoDB一起使用。在检查文件头时,它显示给我

unspecified.csv:应用程序/八位字节流;字符集=二进制

如何使用正确的编码和标题内容存储内容