springboot 返回以base64字符串格式的文件流

springboot接口,返回文件字節流,以base64格式字符串

    @GetMapping("/getFileBase64")
    public String getFileBase64() throws IOException {
        byte[] bytes=null;
        String base64String=null;
        //InputStream inputStream=null;

        File file=new File("D:/本機寬帶密碼和網卡IP.txt");
        FileInputStream fileInputStream=new FileInputStream(file);
        int size=fileInputStream.available();
        bytes=new byte[size];
        fileInputStream.read(bytes);
        fileInputStream.close();

        BASE64Encoder encoder=new BASE64Encoder();
        base64String=encoder.encode(bytes);

        return base64String;
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章