1. 程式人生 > >java-io-檔案相關工具類(全)

java-io-檔案相關工具類(全)

package io.util;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;


public class FileUtil {

    public static final int BUFFER_SIZE = 4096;


    /**
     * formatPath 轉義檔案目錄
     *
     * @param
path * @return */
public static String formatPath(String path) { return path.replaceAll("\\\\", "/"); } /** * combainPath檔案路徑合併 * * @param eins * @param zwei * @return */ public static String combainPath(String eins, String zwei) { String dori = ""
; eins = null == eins ? "" : formatPath(eins); zwei = null == zwei ? "" : formatPath(zwei); if (!eins.endsWith("/") && zwei.indexOf("/") != 0) { dori = eins + "/" + zwei; } else { dori = (eins + zwei).replaceAll("//", "/"); } return
dori; } /** * list2Array 列表轉換陣列 * * @param list * @return */ public static String[] list2Array(List list) { String array[] = (String[]) list.toArray(new String[list.size()]); return array; } /** * cp 複製檔案 * * @param source * @param destination * @param loop * @return */ public static List<File> cp(String source, String destination, boolean loop) { List<File> list = new ArrayList(); try { File srcFile = new File(source); File desFile = new File(destination); list.addAll(cp(srcFile, desFile, loop)); } catch (Exception ex) { j2log(null, null, ex); } return list; } public static void j2log(Object o, Object o1, Exception ex) { ex.printStackTrace(); } /** * cp 複製檔案 * * @param source * @param destination * @param loop * @return */ public static List<File> cp(File source, File destination, boolean loop) { List<File> list = new ArrayList(); try { if (!source.exists() || source.isDirectory()) { throw new FileNotFoundException(); } list.add(cp(source, destination)); if (loop) { String[] subFile = source.list(); for (String subPath : subFile) { String src = combainPath(source.getPath(), subPath);//子檔案原檔案路徑 String des = combainPath(destination.getPath(), subPath);//子檔案目標路徑 File subfile = new File(src); if (subfile.isFile()) { list.add(cp(src, des)); } else if (subfile.isDirectory() && loop) { list.addAll(cp(src, des, loop)); } } } } catch (Exception ex) { j2log(null, null, ex); } return list; } /** * 複製資料夾 * * @param sourceDir * @param targetDir * @throws IOException */ public static void copyDirectiory(String sourceDir, String targetDir) throws IOException { // 新建目標目錄 (new File(targetDir)).mkdirs(); // 獲取原始檔夾當前下的檔案或目錄 File[] file = (new File(sourceDir)).listFiles(); for (int i = 0; i < file.length; i++) { if (file[i].isFile()) { // 原始檔 File sourceFile = file[i]; // 目標檔案 File targetFile = new File(new File(targetDir) .getAbsolutePath() + File.separator + file[i].getName()); if (sourceFile.getName().indexOf(".vax") < 0) cp(sourceFile, targetFile); } if (file[i].isDirectory()) { // 準備複製的原始檔夾 String dir1 = sourceDir + "/" + file[i].getName(); // 準備複製的目標資料夾 String dir2 = targetDir + "/" + file[i].getName(); copyDirectiory(dir1, dir2); } } } /** * cp 單檔案複製檔案 * * @param source * @param destination * @return */ public static File cp(String source, String destination) { File desFile = null; try { File srcFile = new File(source); desFile = new File(destination); desFile = cp(srcFile, desFile); } catch (Exception ex) { j2log(null, null, ex); } return desFile; } /** * cp 單檔案複製檔案 * * @param source * @param destination * @return */ public static File cp(File source, File destination) { FileInputStream in = null; FileOutputStream out = null; FileChannel inc = null; FileChannel outc = null; try { if (!source.exists() || source.isDirectory()) { throw new FileNotFoundException(); } if (source.getPath().equals(destination.getPath())) { return source; } long allbytes = du(source, false); if (!destination.exists()) { destination.createNewFile(); } in = new FileInputStream(source.getPath()); out = new FileOutputStream(destination); inc = in.getChannel(); outc = out.getChannel(); ByteBuffer byteBuffer = null; long length = 2097152;//基本大小,預設2M long _2M = 2097152; while (inc.position() < inc.size()) { if (allbytes > (64 * length)) {//如果檔案大小大於128M 快取改為64M length = 32 * _2M; } else if (allbytes > (32 * length)) {//如果檔案大小大於64M 快取改為32M length = 16 * _2M; } else if (allbytes > (16 * length)) {//如果檔案大小大於32M 快取改為16M length = 8 * _2M; } else if (allbytes > (8 * length)) {//如果檔案大小大於16M 快取改為8M length = 4 * _2M; } else if (allbytes > (4 * length)) {//如果檔案大小大於8M 快取改為4M length = 2 * _2M; } else if (allbytes > (2 * length)) {//如果檔案大小大於4M 快取改為2M length = _2M; } else if (allbytes > (length)) {//如果檔案大小大於2M 快取改為1M length = _2M / 2; } else if (allbytes < length) {//如果檔案小於基本大小,直接輸出 length = allbytes; } allbytes = inc.size() - inc.position(); byteBuffer = ByteBuffer.allocateDirect((int) length); inc.read(byteBuffer); byteBuffer.flip(); outc.write(byteBuffer); outc.force(false); } } catch (Exception ex) { j2log(null, null, ex); } finally { try { if (null != inc) { inc.close(); } if (null != outc) { outc.close(); } if (null != in) { in.close(); } if (null != out) { out.close(); } } catch (Exception ex) { j2log(null, null, ex); } } return destination; } /** * rename 檔案重新命名 * * @param filePath * @param from * @param to * @return */ public static File rename(String filePath, String from, String to) { File newFile = null; try { File oldFile = new File(combainPath(filePath, from)); newFile = new File(combainPath(filePath, to)); rename(newFile, oldFile); } catch (Exception ex) { j2log(null, null, ex); } return newFile; } /** * rename 檔案重新命名 * * @param to * @param from * @return */ public static File rename(File from, File to) { try { String newPath = to.getPath(); String oldPath = from.getPath(); if (!oldPath.equals(newPath)) { if (!to.exists()) { from.renameTo(to); } } } catch (Exception ex) { j2log(null, null, ex); } return to; } /** * mv 移動檔案 * * @param fileName * @param source * @param destination * @param cover */ public static void mv(String fileName, String source, String destination, boolean cover) { try { if (!source.equals(destination)) { File oldFile = new File(combainPath(source, fileName)); File newFile = new File(combainPath(destination, fileName)); mv(oldFile, newFile, cover); } } catch (Exception ex) { j2log(null, null, ex); } } /** * mv 移動檔案 * * @param source * @param destination * @param cover */ public static void mv(String source, String destination, boolean cover) { try { if (!source.equals(destination)) { File oldFile = new File(source); File newFile = new File(destination); mv(oldFile, newFile, cover); } } catch (Exception ex) { j2log(null, null, ex); } } /** * mv 移動檔案 * * @param source * @param destination * @param cover */ public static void mv(File source, File destination, boolean cover) { try { if (!source.exists()) { throw new FileNotFoundException(); } StringBuilder fileName = new StringBuilder(source.getName()); if (!cover && source.getPath().equals(destination.getPath())) { if (fileName.indexOf(".") > 0) { fileName.insert(fileName.lastIndexOf("."), "_副本"); } else { fileName.append("_副本"); } cp(source, new File(combainPath(source.getParent(), fileName.toString()))); } else { source.renameTo(destination); } } catch (Exception ex) { j2log(null, null, ex); } } /** * extensions 獲取副檔名資訊 * * @param filePath * @param fileName * @return */ public static String[] extensions(String filePath, String fileName) { String[] extension = {}; try { String fullPath = combainPath(filePath, fileName); File file = new File(fullPath); extensions(file); } catch (Exception ex) { j2log(null, null, ex); } return extension; } /** * extensions 獲取副檔名資訊 * * @param fullPath * @return */ public static String[] extensions(String fullPath) { String[] extension = {}; try { File file = new File(fullPath); extensions(file); } catch (Exception ex) { j2log(null, null, ex); } return extension; } /** * 判斷目錄是否存在 * * @param strDir * @return */ public static boolean existsDirectory(String strDir) { File file = new File(strDir); return file.exists() && file.isDirectory(); } /** * 判斷檔案是否存在 * * @param strDir * @return */ public static boolean existsFile(String strDir) { File file = new File(strDir); return file.exists(); } /** * 得到檔案的大小 * * @param fileName * @return */ public static int getFileSize(String fileName) { File file = new File(fileName); FileInputStream fis = null; int size = 0; try { fis = new FileInputStream(file); size = fis.available(); } catch (Exception e) { e.printStackTrace(); } return size; } /** * extensions 獲取副檔名資訊 * * @param file * @return */ public static String[] extensions(File file) { String[] extension = {}; try { if (file.isFile()) { String fileName = file.getName(); if (fileName.lastIndexOf(".") >= 0) { int lastIndex = fileName.lastIndexOf("."); extension[0] = String.valueOf(lastIndex);//副檔名的“.”的索引 extension[1] = fileName.substring(lastIndex + 1);//副檔名 extension[2] = fileName.substring(0, lastIndex);//檔名 } } } catch (Exception ex) { j2log(null, null, ex); } return extension; } /** * ls 遍歷檔案 * * @param filePath * @param loop * @return */ public static List<File> ls(String filePath, boolean loop) { List<File> list = new ArrayList(); try { File file = new File(filePath); list.addAll(ls(file, loop)); } catch (Exception ex) { j2log(null, null, ex); } return list; } /** * ls 遍歷檔案 * * @param file * @param loop * @return */ public static List<File> ls(File file, boolean loop) { List<File> list = new ArrayList(); try { list.add(file); if (!file.isDirectory()) { list.add(file); } else if (file.isDirectory()) { File[] subList = file.listFiles(); subList = filesSort(subList, true); for (File subFile : subList) { if (subFile.isDirectory() && loop) { list.addAll(ls(subFile.getPath(), loop)); } else { list.add(subFile); } } } } catch (Exception ex) { j2log(null, null, ex); } return list; } /** * filesSort 檔案排序(預設升序) * * @return */ public static File[] filesSort(File[] inFiles, boolean asc) { List<String> files = new ArrayList(); List<String> dirs = new ArrayList(); for (File subFile : inFiles) { if (subFile.isDirectory()) { dirs.add(subFile.getPath()); } else if (subFile.isFile()) { files.add(subFile.getPath()); } } String[] fileArray = {}; if (files.size() > 0) { fileArray = list2Array(files); Arrays.sort(fileArray); if (!asc) { Arrays.sort(fileArray, Collections.reverseOrder()); } } String[] dirArray = {}; if (dirs.size() > 0) { dirArray = list2Array(dirs); Arrays.sort(dirArray); if (!asc) { Arrays.sort(dirArray, Collections.reverseOrder()); } } return concat2FileArray(fileArray, dirArray); } /** * concat2FileArray 合併檔案陣列 * * @param old1 * @param old2 * @return */ public static File[] concat2FileArray(String[] old1, String[] old2) { File[] newArray = new File[old1.length + old2.length]; for (int i = 0, n = old1.length; i < n; i++) { newArray[i] = new File(old1[i]); } for (int i = 0, j = old1.length, n = (old1.length + old2.length); j < n; i++, j++) { newArray[j] = new File(old2[i]); } return newArray; } /** * read 讀取文字檔案 * * @param filePath * @param fileName * @param charset * @return */ public static StringBuilder read(String filePath, String fileName, String charset) { StringBuilder sb = new StringBuilder(); try { String fullPath = combainPath(filePath, fileName); File file = new File(fullPath); sb.append(FileUtil.tail(file, false, 0, charset)); } catch (Exception ex) { j2log(null, null, ex); } return sb; } /** * read 讀取文字檔案 * * @param fullPath * @param charset * @return */ public static StringBuilder read(String fullPath, String charset) { StringBuilder sb = new StringBuilder(); try { File file = new File(fullPath); sb.append(FileUtil.tail(file, false, 0, charset)); } catch (Exception ex) { j2log(null, null, ex); } return sb; } /** * read 讀取文字檔案 * * @param file * @param charset * @return */ public static StringBuilder read(File file, String charset) { StringBuilder sb = new StringBuilder(); try { sb.append(FileUtil.tail(file, false, 0, charset)); } catch (Exception ex) { j2log(null, null, ex); } return sb; } /** * find 讀取文字檔案指定行 * * @param filePath * @param fileName * @param line * @param charset * @return */ public static StringBuilder find(String filePath, String fileName, int line, String charset) { StringBuilder sb = new StringBuilder(); try { String fullPath = combainPath(filePath, fileName); File file = new File(fullPath); sb.append(FileUtil.tail(file, true, line, charset)); } catch (Exception ex) { j2log(null, null, ex); } return sb; } /** * find 讀取文字檔案指定行 * * @param fullPath * @param line * @param charset * @return */ public static StringBuilder find(String fullPath, int line, String charset) { StringBuilder sb = new StringBuilder(); try { File file = new File(fullPath); sb.append(FileUtil.tail(file, true, line, charset)); } catch (Exception ex) { j2log(null, null, ex); } return sb; } /** * find 讀取文字檔案指定行 * * @param file * @param line * @param charset * @return */ public static StringBuilder find(File file, int line, String charset) { StringBuilder sb = new StringBuilder(); try { sb.append(FileUtil.tail(file, true, line, charset)); } catch (Exception ex) { j2log(null, null, ex); } return sb; } /** * tail 讀取文字檔案 * * @param filePath * @param fileName * @param charset * @param find * @param line * @return */ public static StringBuilder tail(String filePath, String fileName, boolean find, int line, String charset) { StringBuilder sb = new StringBuilder(); try { String fullPath = combainPath(filePath, fileName); File file = new File(fullPath); sb.append(FileUtil.tail(file, find, line, charset)); } catch (Exception ex) { j2log(null, null, ex); } return sb; } /** * tail 讀取文字檔案 * * @param fullPath * @param charset * @param find * @param line * @return */ public static StringBuilder tail(String fullPath, boolean find, int line, String charset) { StringBuilder sb = new StringBuilder(); try { File file = new File(fullPath); sb.append(FileUtil.tail(file, find, line, charset)); } catch (Exception ex) { j2log(null, null, ex); } return sb; } /** * tail 讀取文字檔案 * * @param file * @param charset * @param find * @param line * @return */ public static StringBuilder tail(File file, boolean find, int line, String charset) { StringBuilder sb = new StringBuilder(); BufferedReader bufferReader = null; if (null == charset || "".equals(charset)) { charset = "UTF-8"; } try { if (!file.exists() || file.isDirectory()) { throw new FileNotFoundException(); } String fullPath = file.getPath(); bufferReader = new BufferedReader(new InputStreamReader(new FileInputStream(fullPath), charset)); String temp; for (int i = 0; (temp = bufferReader.readLine()) != null; i++) { if (!find || line == i) { sb.append(temp); } } } catch (Exception ex) { j2log(null, null, ex); } finally { if (null != bufferReader) { try { bufferReader.close(); } catch (IOException ex) { j2log(null, null, ex); } } } return sb; } /** * sed 讀取文字檔案 * * @param filePath * @param fileName * @param charset * @return */ public static List<String> sed(String filePath, String fileName, String charset) { List<String> list = new ArrayList(); try { String fullPath = combainPath(filePath, fileName); File file = new File(fullPath); list.addAll(FileUtil.sed(file, charset)); } catch (Exception ex) { j2log(null, null, ex); } return list; } /** * sed 讀取文字檔案 * * @param fullPath * @param charset * @return */ public static List<String> sed(String fullPath, String charset) { List<String> list = new ArrayList(); try { File file = new File(fullPath); list.addAll(FileUtil.sed(file, charset)); } catch (Exception ex) { j2log(null, null, ex); } return list; } /** * sed 讀取文字檔案 * * @param file * @param charset * @return */ public static List<String> sed(File file, String charset) { List<String> list = new ArrayList(); BufferedReader bufferReader = null; if (null == charset || "".equals(charset)) { charset = "UTF-8"; } try { if (!file.exists() || file.isDirectory()) { throw new FileNotFoundException(); } String fullPath = file.getPath(); bufferReader = new BufferedReader(new InputStreamReader(new FileInputStream(fullPath), charset)); String temp; for (int i = 0; (temp = bufferReader.readLine()) != null; i++) { list.add(temp); } } catch (Exception ex) { j2log(null, null, ex); } finally { if (null != bufferReader) { try { bufferReader.close(); } catch (IOException ex) { j2log(null, null, ex); } } } return list; } /** * cat 讀取文字檔案 * * @param filePath * @param fileName * @return */ public static byte[] cat(String filePath, String fileName) { byte[] output = {}; try { String fullPath = combainPath(filePath, fileName); File file = new File(fullPath); output = FileUtil.cat(file); } catch (Exception ex) { j2log(null, null, ex); } return output; } /** * cat 讀取文字檔案 * * @param fullPath * @return */ public static byte[] cat(String fullPath) { byte[] output = {}; try { File file = new File(fullPath); output = FileUtil.cat(file); } catch (Exception ex) { j2log(null, null, ex); } return output; } /** * cat 讀取文字檔案 * * @param file * @return */ public static byte[] cat(File file) { InputStream in = null; byte[] output = {}; try { if (!file.exists() || file.isDirectory()) { throw new FileNotFoundException(); } String fullPath = file.getPath(); long length = du(file, false); long _2M = 2097152; byte[] bytes = new byte[(int) length]; in = new FileInputStream(fullPath); for (int count = 0; count != -1; ) { if (length > 16 * _2M) { length = 4 * _2M; } else if (length > 8 * _2M) { length = 2 * _2M; } else if (length > 4 * _2M) { length = _2M; } else if (length > 2 * _2M) { length = _2M / 2; } else if (length > _2M) { length = _2M / 4; } else { length = 4096; } bytes = new byte[(int) length]; count = in.read(bytes); output = concatArray(bytes, output); length = in.available(); } } catch (Exception ex) { j2log(null, null, ex); } finally { if (null != in) { try { in.close(); } catch (Exception ex) { j2log(null, null, ex); } } } return output; } /** * 合併陣列 * * @param old1 * @param old2 * @return */ public static byte[] concatArray(byte[] old1, byte[] old2) { byte[] newArray = new byte[old1.length + old2.length]; System.arraycopy(old1, 0, newArray, 0, old1.length); System.arraycopy(old2, 0, newArray, old1.length, old2.length); return newArray; } /** * dd 寫入檔案fullPath內容content * * @param filePath * @param fileName * @param content * @param isAppend */ public static void dd(String filePath, String fileName, byte[] content, boolean isAppend) { try { String fullPath = combainPath(filePath, fileName); File file = new File(fullPath); FileUtil.dd(file, content, isAppend); } catch (Exception ex) { j2log(null, null, ex); } } /** * dd 寫入檔案fullPath內容content * * @param fullPath * @param content * @param isAppend */ public static void dd(String fullPath, byte[] content, boolean isAppend) { try { File file = new File(fullPath); FileUtil.dd(file, content, isAppend); } catch (Exception ex) { j2log(null, null, ex); } } /** * dd 寫入檔案fullPath內容content * * @param file * @param content * @param isAppend */ public static void dd(File file, byte[] content, boolean isAppend) { FileOutputStream fileOutputStream = null; try { if (!file.exists()) { file.createNewFile(); } fileOutputStream = new FileOutputStream(file, isAppend); fileOutputStream.write(content); } catch (Exception ex) { j2log(null, null, ex); } finally { try { if (null != fileOutputStream) { fileOutputStream.close(); } } catch (IOException ex) { j2log(null, null, ex); } } } /** * write 寫檔案內容content到檔案fullPath * * @param filePath * @param fileName * @param content */ public static void write(String filePath, String fileName, String content) { try { String fullPath = combainPath(filePath, fileName); File file = new File(fullPath); FileUtil.write(file, content, true); } catch (Exception ex) { j2log(null, null, ex); } } /** * write 寫檔案內容content到檔案fullPath * * @param fullPath * @param content */ public static void write(String fullPath, String content) { try { File file = new File(fullPath); FileUtil.write(file, content, true); } catch (Exception ex) { j2log(null, null, ex); } } /** * write 寫檔案內容content到檔案fullPath * * @param file * @param content */ public static void write(File file, String content) { try { FileUtil.write(file, content, true); } catch (Exception ex) { j2log(null, null, ex); } } /** * write 寫(追加)檔案內容content到檔案fullPath * * @param filePath * @param fileName * @param content * @param isAppend */ public static void write(String filePath, String fileName, String content, boolean isAppend) { try { String fullPath = combainPath(filePath, fileName); File file = new File(fullPath); FileUtil.write(file, content, isAppend); } catch (Exception ex) { j2log(null, null, ex); } } /** * write 寫(追加)檔案內容content到檔案fullPath * * @param fullPath * @param content * @param isAppend */ public static void write(String fullPath, String content, boolean isAppend) { try { File file = new File(fullPath); FileUtil.write(file, content, isAppend); } catch (Exception ex) { j2log(null, null, ex); } } /** * write 寫(追加)檔案內容content到檔案fullPath * * @param file * @param content * @param isAppend */ public static void write(File file, String content, boolean isAppend) { FileWriter fileWriter = null; try { if (!file.exists()) { file.createNewFile(); } fileWriter = new FileWriter(file.getPath(), isAppend); fileWriter.write(content); } catch (Exception ex) { j2log(null, null, ex); } finally { if (null != fileWriter) { try { fileWriter.close(); } catch (IOException ex) { j2log(null, null, ex); } } } } /** * tail 新增檔案內容content到檔案的index位置 * * @param filePath * @param fileName * @param content * @param index */ public static void tail(String filePath, String fileName, String content, long index) { try { String fullPath = combainPath(filePath, fileName); File file =

相關推薦

java-io-檔案相關工具

package io.util; import java.io.*; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.ArrayList; i

JAVA中的併發工具----控制併發數的Semaphore

本文使用的Demo可以在我的github中找到。 前面我們使用執行緒池技術來控制訪問資源的執行緒數目,假設對某一檔案的訪問,我們允許幾十個執行緒來讀他,但是出於某種限制,我們要求只允許10個執行緒可以同時讀該檔案。這就好比十字路口有100輛車想要過馬路,我們只

java操作ORACLE資料庫工具JDBC

package com.util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSe

Android 農曆和節氣相關工具記錄

中國農曆相關的工具類,可以獲取當前或者規定日期的農曆,節氣,生肖等。 LunarCalender.java package

java常用工具—— 檔案讀取的操作

定義常用的檔案型別 public class FileType { /** * 檔案頭型別 */ public static final String XML_FILE = "text/xml;charset=UTF-8"; public static

常用工具:FileUtile 檔案相關操作

常用工具類(一):FileUtile 檔案相關操作 public class FileUtil { private static final Logger logger = LoggerFactory.getLogger(FileUtils.class); //讀取檔案

java之LineNumberReader,裝飾者模式,列印流,合併流檔案合併和分割和第三方工具FileNameUtils

一.LineNumberReader類 public class Kll { public static void main(String[] args) throws IOException { File file = new File("

java通過http請求工具包含檔案傳輸

package test;import java.io.BufferedReader;import java.io.File;import java.io.IOException;import java.io.InputStreamReader;import java.nio

java網路相關工具是否有網,是否wifi,開啟網路設定介面

/** * 跟網路相關的工具類 * Created by leven on 2016/10/13. */ public class NetUtils { private NetUtil

史上最的開發工具

scp dbi bug 成對 截圖 depend 時間 sre invoke API銀行卡管理 → BankCheckcheckBankCard : 校驗銀行卡卡號是否合法getBankCardCheckCode: 從不含校驗位的銀行卡卡號采用 Luhm

java常用工具—— Map 與 Bean 之間的互相轉換

import net.bytebuddy.implementation.bytecode.Throw; import org.springframework.cglib.beans.BeanMap; import java.beans.PropertyDescriptor; import java.lang

java常用工具—— JSON處理工具

tor ast val simple sta 轉換 local pass password package com.springboot.commons.utils; import com.springboot.commons.scan.JacksonObjectMapp

java常用工具—— Excel 操作工具

import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io

java常用工具—— 文件讀取的操作

() utf-8 cati 解壓縮 操作 char ringbuf 路徑 except 定義常用的文件類型 public class FileType { /** * 文件頭類型 */ public static final Stri

寫爬蟲所用到的工具---3[檔案]

package Tool; import java.io.*; import java.util.ArrayList; import java.util.List; /** * this is a class that can operation file

JAVA常用工具--------------RedisConfig工具

Redis快取用的越來越多,那麼我們是如何使用的Redis? 一,redis的視覺化app 這個是目前比較流行的redis視覺化app。 這是執行狀態的redis,一共擁有16個數據庫,預設儲存在db0裡面。具體儲存的格式,我在 Redis實用教程-----

Java操作JSON的便捷工具Gson

對於JSON資料格式的處理,自開發Java以來,已用過多種JSON的開源工具,用得最好,也用得最High的恐怕要屬Google的Gson了。 特別為它寫了一個工具類,放入常備工具中,方便使用。下面是為GSON 1.5版本重寫的工具類。 依賴包: slf4j-api-1.6.

Java使用POI匯出Excel工具反射

pom.xml: <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId&g

讀取配置檔案工具 properties檔案和xml檔案

讀取properties檔案的工具類 import java.io.File; import java.io.IOException; import java.util.Properties; /** * 讀取properties檔案的工具類 * @author * */ pub

JAVA工具10--- 隨機生成字串工具randomUtil

package com.gcloud.common; import java.util.Random; /** * 隨機數、隨即字串工具 * Created by charlin on 2017/9/9. */ public class RandomU