Created by zl on 2019/03/01.
| 13 | * Created by zl on 2019/03/01. |
| 14 | */ |
| 15 | @Slf4j |
| 16 | public class IOUtil { |
| 17 | |
| 18 | public static byte[] getBytesFromFile(String fileName) throws IOException { |
| 19 | URL url = IOUtil.class.getResource(fileName); |
| 20 | if (url == null) { |
| 21 | log.info("file:{}",fileName); |
| 22 | throw new FileNotFoundException(); |
| 23 | } |
| 24 | log.info("正在读取文件:{}",url.getFile()); |
| 25 | return getBytesFromStream(new FileInputStream(url.getFile())); |
| 26 | } |
| 27 | |
| 28 | public static byte[] getBytesFromStream(FileInputStream in) throws IOException { |
| 29 | FileChannel channel = in.getChannel(); |
| 30 | ByteBuffer buf = ByteBuffer.allocate((int) channel.size()); |
| 31 | channel.read(buf); |
| 32 | channel.close(); |
| 33 | in.close(); |
| 34 | return buf.array(); |
| 35 | } |
| 36 | |
| 37 | |
| 38 | } |
nothing calls this directly
no outgoing calls
no test coverage detected