MCPcopy Create free account
hub / github.com/defineYIDA/LWebServer / IOUtil

Class IOUtil

src/main/java/cn/lws/server/util/IOUtil.java:15–38  ·  view source on GitHub ↗

Created by zl on 2019/03/01.

Source from the content-addressed store, hash-verified

13 * Created by zl on 2019/03/01.
14 */
15@Slf4j
16public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected