org.bcos.web3j.utils.Files Maven / Gradle / Ivy
package org.bcos.web3j.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.bcos.web3j.tx.RawTransactionManager;
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