国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

香港云服务器
服務(wù)器之家 - 編程語(yǔ)言 - JAVA教程 - commons io文件操作示例分享

commons io文件操作示例分享

2019-11-10 15:21java技術(shù)網(wǎng) JAVA教程

這篇文章主要介紹了commons io文件操作示例分享,需要的朋友可以參考下

代碼如下:

package com.pzq.io;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

 

import org.apache.commons.io.FileUtils;


/**
 * 文件操作工具類
 * @version 1.0 2013/07/16
 *
 */
public class FileUtil {

 /**  
     * 復(fù)制文件或者目錄,復(fù)制前后文件完全一樣。  
     * @param resFilePath   源文件路徑  
     * @param distFolder    目標(biāo)文件夾  
     * @IOException         當(dāng)操作發(fā)生異常時(shí)拋出  
     */ 
    public static void copyFile(String resFilePath, String distFolder)  
            throws IOException {  
        File resFile = new File(resFilePath);  
        File distFile = new File(distFolder);  
        if (resFile.isDirectory()) { // 目錄時(shí)  
            FileUtils.copyDirectoryToDirectory(resFile, distFile);  
        } else if (resFile.isFile()) { // 文件時(shí)  
            // FileUtils.copyFileToDirectory(resFile, distFile, true);  
            FileUtils.copyFileToDirectory(resFile, distFile);  
        }  
    }  

    
    /**  
     * 刪除一個(gè)文件或者目錄  
     * @param targetPath     文件或者目錄路徑  
     * @IOException 當(dāng)操作發(fā)生異常時(shí)拋出  
     */ 
    public static void deleteFile(String targetPath) throws IOException {  
        File targetFile = new File(targetPath);  
        if (targetFile.isDirectory()) {  
            FileUtils.deleteDirectory(targetFile);  
        } else if (targetFile.isFile()) {  
            targetFile.delete();  
        }  
    }  

    /**  
     * 將字符串寫(xiě)入指定文件(當(dāng)指定的父路徑中文件夾不存在時(shí),會(huì)最大限度去創(chuàng)建,以保證保存成功!)  
     *   
     * @param res         原字符串  
     * @param filePath    文件路徑  
     * @return 成功標(biāo)記  
     * @throws IOException 
     */ 
    public static boolean string2File(String res, String filePath) throws IOException {  
        boolean flag = true;  
        BufferedReader bufferedReader = null;  
        BufferedWriter bufferedWriter = null;  
        try {  
            File distFile = new File(filePath);  
            if (!distFile.getParentFile().exists()) {// 不存在時(shí)創(chuàng)建  
                distFile.getParentFile().mkdirs();  
            }  
            bufferedReader = new BufferedReader(new StringReader(res));  
            bufferedWriter = new BufferedWriter(new FileWriter(distFile));  
            char buf[] = new char[1024]; // 字符緩沖區(qū)  
            int len;  
            while ((len = bufferedReader.read(buf)) != -1) {  
                bufferedWriter.write(buf, 0, len);  
            }  
            bufferedWriter.flush();  
            bufferedReader.close();  
            bufferedWriter.close();  
        } catch (IOException e) {  
            flag = false;  
            throw e;
        }  
        return flag;  
    }  

    /**  
     * 取得指定文件內(nèi)容 
     *   
     * @param res         原字符串  
     * @param filePath    文件路徑  
     * @return 成功標(biāo)記  
     * @throws IOException 
     */ 
    public static List<String> getContentFromFile(String filePath) throws IOException {  
     List<String> lists = null;
     try {  
      if(!(new File(filePath).exists())){
       return new ArrayList<String>();
      }
      lists = FileUtils.readLines(new File(filePath), Charset.defaultCharset());
     } catch (IOException e) {  
       throw e;
     }  
     return lists;  
    }  

    /**
     * 給指定文件追加內(nèi)容
     * @param filePath
     * @param contents
     */
    public static void addContent(String filePath, List<String> contents) throws IOException { 
      try {
   FileUtils.writeLines(new File(filePath), contents);
  } catch (IOException e) {
    throw e;
  }
    }
}

 

延伸 · 閱讀

精彩推薦
550
主站蜘蛛池模板: 91在线公开视频 | 在线亚洲电影 | 欧美色影院 | 一本久久综合亚洲鲁鲁五月天 | 欧美自拍偷拍 | 成人h免费观看视频 | 国产精品视频 | 久久99精品久久久久久园产越南 | 精品视频久久久 | 色花av | 三区影院| 亚洲欧美第一页 | 奇米亚洲午夜久久精品 | 成人午夜影院 | 欧美二区在线 | 激情欧美日韩一区二区 | 国产成人精品综合 | 日韩欧美精品一区二区三区 | 五月天综合网 | 国产一区二区三区四区二区 | 懂色一区 | 久久精品亚洲精品 | 毛片网站免费在线观看 | 国产综合av | 午夜剧| 欧美午夜精品 | 久久久婷婷 | 992人人tv香蕉国产精品 | 中文字幕第一页在线 | 亚洲热视频在线观看 | 国产精品爱久久久久久久 | 亚洲欧美一区二区三区情侣bbw | 久久精品亚洲一区二区 | 日本福利视频 | 亚洲欧美日韩另类一区二区 | 精品一区二区三区视频 | 4438x成人网最大色成网站 | 中文字幕在线资源 | 亚洲国产精品成人 | 91久久精品国产91久久 | 欧美日韩精品一区二区在线播放 |