本地文件转BASE64|BASE64转文件|解析Excel数据转JSON对象

本地文件转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(
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值