千家信息网

java FastDFS文件下载到本地的方法

发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,本篇内容介绍了"java FastDFS文件下载到本地的方法"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有
千家信息网最后更新 2026年11月03日java FastDFS文件下载到本地的方法

本篇内容介绍了"java FastDFS文件下载到本地的方法"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

package cn.bywin.cbvsp.controller;import cn.bywin.cbvsp.DAL.BO.po.clickhouse.BaseFrameCh;import cn.bywin.cbvsp.DAL.DAO.clickhouse.ClickHouseBaseDao;import com.github.tobato.fastdfs.domain.proto.storage.DownloadByteArray;import com.github.tobato.fastdfs.service.FastFileStorageClient;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import javax.imageio.stream.FileImageOutputStream;import java.io.File;import java.util.HashSet;import java.util.List;/** * @author linbin * @create 2019-07-25 15:37 */@RestController@Component@RequestMapping("linbin")public class DownLoadController {    @Autowired    private ClickHouseBaseDao clickHouseBaseDao;    @Autowired    private FastFileStorageClient storageClient;    @PostMapping("/download")    public void test() {        //查找这个时间段的所有摄像头        List strings1 = clickHouseBaseDao.selectByTime("select video_source_id from cbvsp.base_fragment  where real_time between  '2019-07-24 20:00:00'  and '2019-07-24 20:10:00'");        HashSet s = new HashSet<>();        strings1.forEach(e->{            s.add(e);        });        for (String s1 : s) {            List strings = clickHouseBaseDao.selectByTime("select file_id from cbvsp.base_fragment where real_time between  '2019-07-24 20:00:00'  and '2019-07-24 20:10:00' and video_source_id='"+s1+"';");            buildFolder("/home/deploy/191-20to820-video/"+s1+"");            strings.forEach(e -> {                if(e.contains("35.26.59.199")){                    return;                }                testHome(e,s1);            });        }    }    public void testHome(String fileUrl,String dir) {        String path = fileUrl.substring(32);        int i = path.indexOf('/');        int i2 = path.indexOf("/", i + 1);        int i3 = path.indexOf("/", i2 + 1);        String ss = path.substring(i3 + 1);        DownloadByteArray downloadByteArray = new DownloadByteArray();        byte[] bytes = storageClient.downloadFile("group1", path, downloadByteArray);        byte2image(bytes, "/home/deploy/191-20to820-video/"+dir+"/" + ss);    }    //byte数组到图片到硬盘上    public void byte2image(byte[] data, String path) {        if (data.length < 3 || path.equals("")) return;//判断输入的byte是否为空        try {            FileImageOutputStream imageOutput = new FileImageOutputStream(new File(path));//打开输入流            imageOutput.write(data, 0, data.length);//将byte写入硬盘            imageOutput.close();            System.out.println("Make Picture success,Please find image in " + path);        } catch (Exception ex) {            System.out.println("Exception: " + ex);            ex.printStackTrace();        }    }    public static String buildFolder(String path) {        //读取目录路径        File file = new File(path);        //推断是否存在        if (!file.exists() && !file.isDirectory()) {            try {                System.out.println("目录不存在!");                //生成目录                file.mkdir();            } catch (Exception e) {                e.printStackTrace();            }        } else {            System.out.println("目录存在!");        }        return path;    }}

"java FastDFS文件下载到本地的方法"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

目录 文件 文件下载 方法 内容 更多 知识 硬盘 输入 实用 学有所成 接下来 困境 图片 实际 情况 摄像头 数组 文章 时间 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网科技 广州紫鲸互联网科技有限公司 互联网科技公司华为 互联网科技行业发展 河南真二互联网科技有限公司 极限挑战互联网科技 广州紫鲸互联网科技 成都狮子座互联网科技 互联网科技大会案例 联恩商钥互联网科技有限公司 顺网科技2021年互联网排名 来此购互联网科技有限公司 智腾互联网科技有限公司 杭州壁岐互联网科技有限公司 广州千川互联网科技有限公司 风投北京互联网科技 南京一网一红互联网科技有限公司 广州梦谷互联网科技有限公司领导 好易买互联网科技 前海云享互联网科技 广州百单互联网科技有限公司 丰台科技园 互联网公司 成都铂石互联网科技做什么的 武汉健翔互联网络科技有限公司 区块链结合互联网科技 广州富喜互联网络科技 城市宝互联网科技有限公司 工业互联网科技创业 青岛易易互联网科技 科技互联网企业在行动
0