小编esg*_*oth的帖子

将字节数组写入文件.并不总是得到预期的结果

我正在使用Java将字节数组写入文件.当我在十六进制编辑器中打开我的文件时,我并不总是看到我期望在那里的字节.这是我的示例代码和输出文件的内容:

public static void main(String[] args) 
{
    File file = new File( "c:\\temp\\file.txt" );
    file.delete();
    FileOutputStream outStream = null;
    try 
    {
        file.createNewFile();
    } catch (IOException e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try 
    {
        outStream = new FileOutputStream( file );
    } catch (FileNotFoundException e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try 
    {
    outStream.write( new byte[] { 0x14, 0x00, 0x1F, 0x50 } );

    } catch (IOException e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在十六进制编辑器中打开文件时,我获取 …

java arrays byte file fileoutputstream

5
推荐指数
1
解决办法
1614
查看次数

标签 统计

arrays ×1

byte ×1

file ×1

fileoutputstream ×1

java ×1