0

我正在使用下面的代码从“.264”文件中读取。

public static void main (String[] args) throws IOException
{

    BufferedReader br = null;try {
        String sCurrentLine;
        br = new BufferedReader(new InputStreamReader(new FileInputStream("test.264"),"ISO-8859-1"));
        StringBuffer stringBuffer = new StringBuffer();
        while ((sCurrentLine = br.readLine()) != null) {
            stringBuffer.append(sCurrentLine);      
        }
        String tempdec = new String(asciiToHex(stringBuffer.toString()));
        System.out.println(tempdec);
        String asciiEquivalent = hexToASCII(tempdec);
        BufferedWriter xx = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:/Users/Administrator/Desktop/yuvplayer-2.3/video dinalized/testret.264"),"ISO-8859-1"));
        xx.write(asciiEquivalent);
        xx.close();
    }catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null)br.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

}

在 HEX 编辑器中打开输入和输出文件会显示一些缺失值,例如0d(见附图)。

有什么解决方案可以解决这个问题吗?

图像1 图2

4

1 回答 1

1

失去InputStreamReaderand BufferedReader,只使用FileInputStream它自己。
没有字符编码,没有行尾,只有字节。
它的 Javadoc 页面在这里,这应该是你所需要的。

如果您想一次读取整个文件,请提示:File.length(),如

File file = new File("test.264");
byte[] buf = new byte[(int)file.length()];
// Use buf in InputStream.read()
于 2015-04-25T09:34:14.973 回答