简体   繁体   English

从文件读取字节

[英]Reading bytes from a file

I am reading from a ".264" file using code below. 我正在使用以下代码从“ .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();
        }
    }

}

Opening input and output file in HEX Editor show me some missing values, eg 0d (see pictures attached). 在HEX编辑器中打开输入和输出文件会显示一些缺少的值,例如0d (请参阅所附图片)。

Any solution to fix this? 有解决方案吗?

此搜索图像2

Lose InputStreamReader and BufferedReader , just use FileInputStream on its own. 失去InputStreamReaderBufferedReader ,仅使用FileInputStream
No character encoding, no line endings, just bytes. 没有字符编码,没有行尾,只有字节。
Its Javadoc page is here , that should be all you need. 它的Javadoc页面在这里 ,这应该是您所需要的。

Tip if you want to read the entire file at once: File.length() , as in 提示:如果您想一次读取整个文件: File.length() ,如

File file = new File("test.264");
byte[] buf = new byte[(int)file.length()];
// Use buf in InputStream.read()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM