mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2025-06-25 14:32:42 +08:00
1.2.7 FileUtil增加base64转File
This commit is contained in:
parent
30ce976b27
commit
5b79c1b383
@ -1,6 +1,13 @@
|
|||||||
yexuejc-base 更新记录
|
yexuejc-base 更新记录
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
#### version :1.2.7
|
||||||
|
**time:2018-12-24 15:31:01** <br/>
|
||||||
|
**branch:** master <br/>
|
||||||
|
**update:** <br/>
|
||||||
|
>1. FileUtil增加base64转File `base64ToFile()`
|
||||||
|
|
||||||
|
#
|
||||||
#### version :1.2.6
|
#### version :1.2.6
|
||||||
**time:2018-12-21 14:58:49** <br/>
|
**time:2018-12-21 14:58:49** <br/>
|
||||||
**branch:** master <br/>
|
**branch:** master <br/>
|
||||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.yexuejc.base</groupId>
|
<groupId>com.yexuejc.base</groupId>
|
||||||
<artifactId>yexuejc-base</artifactId>
|
<artifactId>yexuejc-base</artifactId>
|
||||||
<version>1.2.6</version>
|
<version>1.2.7</version>
|
||||||
|
|
||||||
<name>${project.artifactId}</name>
|
<name>${project.artifactId}</name>
|
||||||
|
|
||||||
|
@ -2,10 +2,7 @@ package com.yexuejc.base.util;
|
|||||||
|
|
||||||
import sun.misc.BASE64Encoder;
|
import sun.misc.BASE64Encoder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.nio.MappedByteBuffer;
|
import java.nio.MappedByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
@ -307,6 +304,37 @@ public class FileUtil {
|
|||||||
return encoder.encode(data);
|
return encoder.encode(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* base64转文件
|
||||||
|
* <p>
|
||||||
|
* <i>
|
||||||
|
* 文件转base64请使用 {@link FileUtil#base64(File)}
|
||||||
|
* </i>
|
||||||
|
*
|
||||||
|
* @param decode baseByte
|
||||||
|
* @param fileName 文件名称(包含路径)
|
||||||
|
* @return 返回保存地址
|
||||||
|
*/
|
||||||
|
public static String base64ToFile(byte[] decode, String fileName) {
|
||||||
|
|
||||||
|
FileOutputStream out = null;
|
||||||
|
try {
|
||||||
|
out = new FileOutputStream(fileName);
|
||||||
|
out.write(decode);
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
ioe.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (out != null) {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件大小 :直接返回大小
|
* 获取文件大小 :直接返回大小
|
||||||
*
|
*
|
||||||
|
@ -323,33 +323,6 @@ public class ImgUtil {
|
|||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* base64转文件
|
|
||||||
*
|
|
||||||
* @param decode baseByte
|
|
||||||
* @param fileName 文件名称(包含路径)
|
|
||||||
* @return 返回保存地址
|
|
||||||
*/
|
|
||||||
public static String base64ToFile(byte[] decode, String fileName) {
|
|
||||||
|
|
||||||
FileOutputStream out = null;
|
|
||||||
try {
|
|
||||||
out = new FileOutputStream(fileName);
|
|
||||||
out.write(decode);
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
ioe.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (out != null) {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ImageInfo {
|
public static class ImageInfo {
|
||||||
/**
|
/**
|
||||||
* 图片大小
|
* 图片大小
|
||||||
|
Loading…
x
Reference in New Issue
Block a user