集册 Java实例教程 从文件中读取4个字节,然后从RandomAccessFile中将其解释为UINT32。

从文件中读取4个字节,然后从RandomAccessFile中将其解释为UINT32。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

617
从文件中读取4个字节,然后从RandomAccessFile中将其解释为UINT32。


//package com.nowjava;

import java.io.IOException;

import java.io.RandomAccessFile;/** from 时 代 J a v a 公 众 号 - N o w J a v  a . c o m**/


public class Main {

    /**

     * Reads 4 bytes from file and interprets them as UINT32.<br>

     * 

     * @param raf

     *            file to read from.

     * @return UINT32 value

     * @throws IOException

     *             on I/O Errors.

     */

    public static long readUINT32(RandomAccessFile raf) throws IOException {

        long result = 0;

        for (int i = 0; i < 4; i++) {

            // Warning, always cast to long here. Otherwise it will be

            // shifted as int, which may produce a negative value, which will

            
展开阅读全文