我有一个 hadoop 作业,其最终输出如下
String myKey = "myKey";
context.write(myKey, myObjectWritable.toByteArray());
我的输出文件如下所示
myKey/t00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
我的问题是如何将字符串中的字节转换为byte[]
,因为该文件由字符串和写入为字符串的字节组成。
try (BufferedReader br = new BufferedReader(new FileReader("my_map_reduce_file"))) {
String line;
while ((line = br.readLine()) != null) {
String[] x = line.split("\t");
// how do I convert x[1] to byte[]
}
最佳答案
String mykey = "myKey";
byte[] mykey_byte_array = mykey.getBytes(StandardCharsets.UTF_8);
System.out.println("contents of byte array " + Arrays.toString(mykey_byte_array));
关于java - 如何将文件中的字节转换为java中的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58310117/