All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fisco.bcos.web3j.utils.Files Maven / Gradle / Ivy

There is a newer version: 2.6.6
Show newest version
package org.fisco.bcos.web3j.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * File utility functions.
 */
public class Files {
    static Logger logger = LoggerFactory.getLogger(Files.class);
    private Files() { }

    public static byte[] readBytes(File file) throws IOException {
        byte[] bytes = new byte[(int) file.length()];
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(file);
            fileInputStream.read(bytes);
        }catch (Exception e)
        {
            logger.error("readBytes error :", e);
            throw e;
        }finally {
            if (fileInputStream != null) {
                fileInputStream.close();
            }
        }
        return bytes;
    }

    public static String readString(File file) throws IOException {
        return new String(readBytes(file));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy