本地文件转BASE64|BASE64转文件|解析Excel数据转JSON对象
废话不多说,直接上代码
对应依赖:
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aspose/aspose-words -->
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>15.8.0</version>
</dependency>
测试类:
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import java.io.*;
import java.lang.reflect.Field;
import java.util.*;
public class Test {
/**
*测试:将文件编码为base64字符串
*/
public static String base64Encode() throws Exception {
// 将文件转化为输入流
String filePath = "F:\\data.xlsx";
File file = new File(filePath);
InputStream inputStream = new FileInputStream(file);
// 将InputStream转化为byte[]
// 如果使用byte[] byte = new byte[input.available()];这种方式会出现字节码全为0的情况,原因未知
ByteArrayOutputStream bos = new ByteArrayOutputStream(