Java 如何忽略hdfs writeUTF和writeChars的前两个字节?

Java 如何忽略hdfs writeUTF和writeChars的前两个字节?,java,hadoop,hdfs,Java,Hadoop,Hdfs,我已经在hdfs中写入了一些数据,但我希望它不包含writeUTF()方法写入的前两个字节。我想将这个前两个字节的免费hdfs文件复制到本地文件,并对其进行一些分析 if (fs.exists(filenamePath)) { // remove the file first //fs.delete(filenamePath); out = fs.append(filenamePath); } // create if file

我已经在hdfs中写入了一些数据,但我希望它不包含writeUTF()方法写入的前两个字节。我想将这个前两个字节的免费hdfs文件复制到本地文件,并对其进行一些分析

if (fs.exists(filenamePath)) {
        // remove the file first
        //fs.delete(filenamePath);
         out = fs.append(filenamePath);
    }
    // create if file doesnt exists
    else{
        out = fs.create(filenamePath);
    }

    out.writeUTF(getFeaturesString(searchCriteriaList,fileNameData));
    out.close();
写的数据如下

0aEX Series ex4200-24f....
我只要

EX Series   ex4200-24f  
我将所有数据写入hdfs文件,然后将该文件复制到本地进行分析。是否有其他方法来实现这一点

如何忽略头两个字节hdfs
writeUTF()
writeChars()

你刚刚回答了你自己的问题。使用
writeChars()

writeUTF()
仅在有人要调用
readUTF()
读取它时才有用。它使用一个修改过的字符集和一个只有
readUTF()
才能理解的长度字


这里也没有特别的理由使用
DataOutputStream
。如果数据都是文本,请使用
BufferedWriter。

当我使用writeChars()方法时,文件开头没有特殊字符,但每个字母后都有不需要的空格。例如:“E X S E r i E S”。我可以做我的工作,但我只是想知道这种行为