文件流读取文件中的内容

io流读取文件中的内容

public class test {

    public static void main(String[] args) {

        String path = "E:\\WorkSpace\\a.txt";
        readFile(path);
        
    }

    public static void readFile(String path){
        try {
            FileInputStream inputStream = new FileInputStream(path) ;
            byte[] bytes = new byte[1024];
            inputStream.read(bytes);//参数为存取数据的字节数组
            //将byte[]——> string
            String content = new String(bytes);
            System.out.println(content);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

猜你喜欢

转载自blog.csdn.net/qq_43039260/article/details/90730333