forked from nibnait/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBase64Convert.java
More file actions
35 lines (30 loc) · 988 Bytes
/
Base64Convert.java
File metadata and controls
35 lines (30 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package zzzTest;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class Base64Convert {
public static void main(String[] args) throws IOException {
String fileBase64Code = getBaseCode();
System.out.println(fileBase64Code);
}
/**
* 将文件转化为字节数组字符串,并对其进行Base64编码处理
* @return
*/
private static String getBaseCode() throws IOException {
InputStream in = null;
byte[] data = null;
try {
in = new FileInputStream("/Users/nibnait/Desktop/食安风险-店铺投诉2017.05.10.xlsx");
data = new byte[in.available()];
in.read(data);
} catch (Exception e) {
e.printStackTrace();
} finally {
in.close();
}
// 返回Base64编码过的字节数组字符串
return Base64.getEncoder().encodeToString(data);
}
}