bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

如何用代碼拷貝一個文件到另一個目錄下

這篇文章主要介紹“如何用代碼拷貝一個文件到另一個目錄下”,在日常操作中,相信很多人在如何用代碼拷貝一個文件到另一個目錄下問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”如何用代碼拷貝一個文件到另一個目錄下”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

成都網站建設、網站設計的關注點不是能為您做些什么網站,而是怎么做網站,有沒有做好網站,給成都創新互聯一個展示的機會來證明自己,這并不會花費您太多時間,或許會給您帶來新的靈感和驚喜。面向用戶友好,注重用戶體驗,一切以用戶為中心。

    public Map<String, String> imageUpload(String path, String sensorNo,String presetNo, String channelNo) 
        Map<String, String> map = new HashMap<>();
        // 讀取圖片
        File fileImage = new File(path); // E:\picture\1\20210409\66666.png
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(fileImage);// 建立一個輸入流對象
        } catch (FileNotFoundException e1) {
            log.error("read file error{}", e1);
        }
        String fileDocment = null; // 寫入路徑
        if (System.getProperty("os.name").toLowerCase().contains("windows")) {
            
            BaseSysconfig baseSysconfig     = baseSysconfigRepository.findByParamCode("ElectronicfenceW");
            fileDocment = baseSysconfig.getCurrentlyValue() + File.separator + "zhqb_electronicfence"
                    + File.separator + sensorNo.replace(" ", "") + File.separator
                    + presetNo.replace(" ", "") + File.separator
                    + channelNo.replace(" ", "");
        } else {
            // 拼接上傳路徑 /datacenter/zhqb_electronicfence/攝像頭編號/預置位編號/通道編號/圖片名
            BaseSysconfig baseSysconfig     = baseSysconfigRepository.findByParamCode("ElectronicfenceL");
            fileDocment = baseSysconfig+ File.separator
                    + sensorNo.replace(" ", "") + File.separator
                    + presetNo.replace(" ", "") + File.separator
                    + channelNo.replace(" ", "");
        }

        String filepath = fileDocment + File.separator + fileImage.getName();
        // 寫入路徑
        File fileParent = new File(fileDocment);// 新建文件目錄
        if (!fileParent.exists()) {// 不存在則創建路徑
            fileParent.mkdirs();
        }
        File fileElectronicFence = new File(filepath);  //filePath 要寫的目錄
        FileOutputStream fos = null;
        if (!fileElectronicFence.exists()) {
            try {
                fileElectronicFence.createNewFile();
                fos = new FileOutputStream(filepath);
                byte[] buf = new byte[1024];// 每次讀入文件數據量
                int len = -1;
                while ((len = (fis.read(buf))) != -1) {
                    fos.write(buf);
                    fos.flush();
                }
            } catch (IOException e) {
                log.error("create file error{}", e);
            } finally {

                try {
                    fos.flush();
                    fos.close();
                    fis.close();
                } catch (IOException e) {
                    log.error("close OutputStream fail{}", e);
                }
            }
        }
        map.put("status", "sucess");
        map.put("path", filepath);
        return map;
    }

到此,關于“如何用代碼拷貝一個文件到另一個目錄下”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注創新互聯網站,小編會繼續努力為大家帶來更多實用的文章!

本文題目:如何用代碼拷貝一個文件到另一個目錄下
轉載來于:http://vcdvsql.cn/article4/gjspie.html

成都網站建設公司_創新互聯,為您提供網站制作、網站改版、建站公司、關鍵詞優化服務器托管、網站設計公司

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都網頁設計公司