package com.ff.weijinxiao.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;

public class FileUtil {

    /**
     * 读取图片文件，转成byte[]存入mysql
     *
     * @param filePath
     * @return byte[]
     * @throws IOException
     */
    public static byte[] readByteFromFilePath(String filePath) throws IOException {
        File file = new File(filePath);
        InputStream input = new FileInputStream(file);
        byte[] byt = new byte[input.available()];
        input.read(byt);
        return byt;
    }

    /**
     * 根据上传时间生成文件名
     *
     * @return
     */
    public static String gerenalFileName() {
        java.util.Date dt = new java.util.Date(System.currentTimeMillis());
        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        return fmt.format(dt);
    }
}
