package com.wondream.myframework.app.basictest.io; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.Test; import org.springframework.util.ResourceUtils; import java.io.File; import java.io.FileInputStream; public class FileInputStreamTest { private final Log logger = LogFactory.getLog(FileInputStreamTest.class); @Test void excute(){ File file = null; FileInputStream fileInputStream = null; try{ // 读取文件方式一 spring中工具类 file = ResourceUtils.getFile("classpath:application.properties"); fileInputStream = new FileInputStream(file); // 根据输入流可用大小 定义缓冲区 byte[] data = new byte[fileInputStream.available()]; // 读取数据到字节数组 fileInputStream.read(data); String var1 = new String(data, "UTF-8"); logger.info(var1); // 用完关闭流 fileInputStream.close(); }catch (Exception e){ e.printStackTrace(); } } }
FileInputStream的基本使用
最新推荐文章于 2023-05-18 20:10:38 发布