JAVA中文件与Byte数组相互转换的方法,如下: public class FileUtil { //将文件转换成Byte数组 public static byte[] getBytesByFile(String pathStr) { File file = new File(pathStr); try { FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream bos = new ByteArrayOutp…
//加了了Optional防止空指针异常,加入了泛型,省去了强制转化 import java.io.*; import java.util.Optional; /** * Created by Jason on 2017/1/3. */ public class ByteArrayUtils { public static<T> Optional<byte[]> objectToBytes(T obj){ byte[] bytes = null; ByteArrayOutputSt…