JAVA中使用openoffice将Excel转PDF再转图片功能的实现代码

需求

公司一个小项目要结尾了, 有非常多的表格, 而且非常复杂, 例如

例如:(这表格, 有想死的心…)

看到这样的表格,第一反应是n脸懵逼,这得做到啥时候啊,最后想到用一个方法,让客户自己玩!!
平台提供Excel模版下载,客户下载填写完再提交Excel,平台再将Excel转PDF,顺便将PDF转成图片,给前端展示,想法简单,方案可行,开工!

方案:

  • windows server下用 jacob, windows上可完美运行, 但是!!!Linux上不支持jacob!!!(非常重要!!)
  • poi + iText,貌似不错
  • openoffice,跨平台

本文选用openoffice,各位看官可自选用iText + poi,自己判别!当然也可以用jacob,前提是你不需要在Linux中运行项目。

安装软件:下载传送门

win:

下载完成后,一路next,最好默认路径安装,免得折腾
完成后 Win + R 填入 Dcomcnfg 打开组件服务

设置openoffice组件服务, 都设成SYSTEM

再设置标识为:交互式用户

进入到安装目录,如果路径是默认的,则在 C:\Program Files (x86)\OpenOffice 4\program 下面,
进到这个路径下,按住 shift 再点击鼠标右键,在此处打开命令窗口,输入 soffice -headless-accept=“socket,host=127.0.0.1,port=8100;urp;”-nofirststartwizard, 查看是否启动成功, 黑窗口输入 netstat -ano


windows下安装完毕!

参考: https://blog.csdn.net/qq_30987095/article/details/78789103

linux:下载传送门

根据自己的Linux系统选择RPM包或者DEB,如果是Ubuntu则选DEB,其他就选RPM包,查看当前操作系统是ubuntu还是centos

[root@iZ2zeg3etf08f6snef3lgrZ ~]#  lsb_release -a
LSB Version:	:(略)
Distributor ID:	CentOS
Description:	CentOS Linux release (略)
Release:	(略)
Codename:	Core

下载完毕后,利用ssh工具上传到服务器上!

>  tar -zxvf Apache_OpenOffice_4.1.3_Linux_x86-64_install-rpm_zh-CN.tar.gz
(略)......

> ls
zh-CN
> cd zh-CN/RPMS
> ls
openoffice-core01-4.1.3-9783.x86_64.rpm             openoffice-impress-4.1.3-9783.x86_64.rpm        openoffice-zh-CN-4.1.3-9783.x86_64.rpm
openoffice-4.1.3-9783.x86_64.rpm                openoffice-core02-4.1.3-9783.x86_64.rpm             openoffice-javafilter-4.1.3-9783.x86_64.rpm     openoffice-zh-CN-base-4.1.3-9783.x86_64.rpm
openoffice-base-4.1.3-9783.x86_64.rpm           openoffice-core03-4.1.3-9783.x86_64.rpm             openoffice-math-4.1.3-9783.x86_64.rpm           openoffice-zh-CN-calc-4.1.3-9783.x86_64.rpm
openoffice-brand-base-4.1.3-9783.x86_64.rpm     openoffice-core04-4.1.3-9783.x86_64.rpm             openoffice-ogltrans-4.1.3-9783.x86_64.rpm       openoffice-zh-CN-draw-4.1.3-9783.x86_64.rpm
openoffice-brand-calc-4.1.3-9783.x86_64.rpm     openoffice-core05-4.1.3-9783.x86_64.rpm             openoffice-onlineupdate-4.1.3-9783.x86_64.rpm   openoffice-zh-CN-help-4.1.3-9783.x86_64.rpm
openoffice-brand-draw-4.1.3-9783.x86_64.rpm     openoffice-core06-4.1.3-9783.x86_64.rpm             openoffice-ooofonts-4.1.3-9783.x86_64.rpm       openoffice-zh-CN-impress-4.1.3-9783.x86_64.rpm
openoffice-brand-impress-4.1.3-9783.x86_64.rpm  openoffice-core07-4.1.3-9783.x86_64.rpm             openoffice-ooolinguistic-4.1.3-9783.x86_64.rpm  openoffice-zh-CN-math-4.1.3-9783.x86_64.rpm
openoffice-brand-math-4.1.3-9783.x86_64.rpm     openoffice-draw-4.1.3-9783.x86_64.rpm               openoffice-pyuno-4.1.3-9783.x86_64.rpm          openoffice-zh-CN-res-4.1.3-9783.x86_64.rpm
openoffice-brand-writer-4.1.3-9783.x86_64.rpm   openoffice-gnome-integration-4.1.3-9783.x86_64.rpm  openoffice-ure-4.1.3-9783.x86_64.rpm            openoffice-zh-CN-writer-4.1.3-9783.x86_64.rpm
openoffice-brand-zh-CN-4.1.3-9783.x86_64.rpm    openoffice-graphicfilter-4.1.3-9783.x86_64.rpm      openoffice-writer-4.1.3-9783.x86_64.rpm
openoffice-calc-4.1.3-9783.x86_64.rpm           openoffice-images-4.1.3-9783.x86_64.rpm             openoffice-xsltfilter-4.1.3-9783.x86_64.rpm

[注释:运行下面命令, 生成  desktop-integration包]
>  yum localinstall *.rpm
> (略...)
> cd desktop-integration/
> ls
>  openoffice4.1.3-freedesktop-menus-4.1.3-9783.noarch.rpm
   openoffice4.1.3-mandriva-menus-4.1.3-9783.noarch.rpm
   openoffice4.1.3-redhat-menus-4.1.3-9783.noarch.rpm
   openoffice4.1.3-suse-menus-4.1.3-9783.noarch.rpm

>  yum localinstall  openoffice4.1.3-redhat-menus-4.1.3-9783.noarch.rpm

ok, 安装完毕了! 启动服务
进入到默认安装目录下

> cd /opt/openoffice4/program/
[注释:临时启动]
> /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
[注释:或后台启动]
> /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &

[注释:永久启动]
> nohup /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &

[注释:查看是否启动成功]
> ps -ef|grep openoffice
root      7541  7527  0 10:19 pts/0    00:00:12 /opt/openoffice4/program/soffice.bin -headless -accept=socket,host=127.0.0.1,port=8100;urp; -nofirststartwizard
root      8964  7066  0 18:18 pts/3    00:00:00 grep --color=auto openoffice

或者

> netstat -tunlp |grep
tcp        0      0 127.0.0.1:8100          0.0.0.0:*               LISTEN      7541/soffice.bin

Linux下安装成功!

开始撸码:

pom.xml

		<!-- openoffice 相关依赖 -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>juh</artifactId>
            <version>3.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>ridl</artifactId>
            <version>3.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>unoil</artifactId>
            <version>3.2.1</version>
        </dependency>

	    <!-- pdf2img -->
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>2.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox-tools</artifactId>
            <version>2.0.6</version>
        </dependency>

OpenOfficeUtils

import java.awt.*;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ConnectException;

import org.apache.commons.lang.StringUtils;

import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.DocumentFormatRegistry;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
import com.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageTree;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.pdfbox.tools.imageio.ImageIOUtil;

import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;

/**
 *
 * @author josnow
 * @date 2017年5月9日 下午12:38:39
 * @version 1.0.0
 * @desc openoffice转换工具
 */
public class OpenOfficeUtils {

    public static final String LOCAL_HOST = "localhost";
    public static final int LOCAL_PORT = 8100;

    // Format
    public static DocumentFormatRegistry formatFactory = new DefaultDocumentFormatRegistry();

    /**
     *
     * @desc
     * @auth josnow
     * @date 2017年6月9日 下午4:11:04
     * @param inputFilePath
     *            待转换的文件路径
     * @param outputFilePath
     *            输出文件路径
     */
    public static void convert(String inputFilePath, String outputFilePath) throws ConnectException {
        convert(inputFilePath, outputFilePath, LOCAL_HOST, LOCAL_PORT);
    }

    /**
     *
     * @desc
     * @auth josnow
     * @date 2017年6月9日 下午4:12:29
     * @param inputFilePath
     *            待转换的文件路径
     * @param outputFilePath
     *            输出文件路径
     * @param connectIp
     *            远程调用ip
     * @param connectPort
     *            远程调用端口
     */
    public static void convert(String inputFilePath, String outputFilePath, String connectIp, int connectPort)
            throws ConnectException {
        if (StringUtils.isEmpty(inputFilePath) || StringUtils.isEmpty(outputFilePath)
                || StringUtils.isEmpty(connectIp)) {
            throw new IllegalArgumentException("参数异常!!");
        }
        OpenOfficeConnection connection = new SocketOpenOfficeConnection(connectIp, connectPort);
        connection.connect();

// 		  TODO Excel转成PDF默认是A4纸
//        DocumentConverter converter = getConverter(connectIp, connection);
//        converter.convert(new File(inputFilePath), new File(outputFilePath));

// 		  TODO Excel转成PDF默认是A4纸, 如果现实折行,则自定义ConverterDocument,改变纸张大小
        ConverterDocument converterDocument = new ConverterDocument(connection);
        converterDocument.convert(new File(inputFilePath), new File(outputFilePath));

        connection.disconnect();
    }

    /**
     *
     * @desc
     * @auth josnow
     * @date 2017年6月9日 下午4:08:26
     * @param inputStream
     * @param inputFileExtension
     *            待转换文件的扩展名,例如: xls,doc
     * @param outputStream
     * @param outputFileExtension
     *            输出文件扩展名,例如:pdf
     */
    public static void convert(InputStream inputStream, String inputFileExtension, OutputStream outputStream,
            String outputFileExtension) throws ConnectException {
        convert(inputStream, inputFileExtension, outputStream, outputFileExtension, LOCAL_HOST, LOCAL_PORT);
    }

    /**
     *
     * @desc
     * @auth josnow
     * @date 2017年6月9日 下午4:10:21
     * @param inputStream
     * @param inputFileExtension
     *            待转换文件的扩展名,例如: xls,doc
     * @param outputStream
     * @param outputFileExtension
     *            输出文件扩展名,例如:pdf
     * @param connectIp
     *            远程调用ip
     * @param connectPort
     *            远程调用端口
     */
    public static void convert(InputStream inputStream, String inputFileExtension, OutputStream outputStream,
            String outputFileExtension, String connectIp, int connectPort) throws ConnectException {

        if (inputStream == null || StringUtils.isEmpty(inputFileExtension) || outputStream == null
                || StringUtils.isEmpty(outputFileExtension) || StringUtils.isEmpty(connectIp)) {
            throw new IllegalArgumentException("参数异常!!");
        }

        OpenOfficeConnection connection = new SocketOpenOfficeConnection(connectIp, connectPort);
        connection.connect();
        DocumentConverter converter = getConverter(connectIp, connection);

        converter.convert(inputStream, formatFactory.getFormatByFileExtension(inputFileExtension), outputStream,
                formatFactory.getFormatByFileExtension(outputFileExtension));
        connection.disconnect();
    }

    private static DocumentConverter getConverter(String connectIp, OpenOfficeConnection connection) {
        DocumentConverter converter = "localhost".equals(connectIp) || "127.0.0.1".equals(connectIp)
                || "0:0:0:0:0:0:0:1".equals(connectIp) ? new OpenOfficeDocumentConverter(connection)
                        : new StreamOpenOfficeDocumentConverter(connection);
        return converter;
    }

    public static void main(String[] args) throws Exception {
        OpenOfficeUtils.convert("D:\\test.xls", "D:\\test.pdf");
        pdf2image(new File("D:\\test.pdf"));
    }

    /**
     * pdf to big image
     * github: https://github.com/mmtou/pdf2img
     * @param pdfFile pdf文件路径
     * @return big image file
     * @throws Exception
     */
    public static File pdf2image(File pdfFile) throws Exception {
        // 拼成图片后的宽度和高度
        int w = 0;
        int h = 0;
        List<BufferedImage> images = new ArrayList();
        // 生成图片后的路径
        String path = pdfFile.getParent() + File.separator;
        String fileName = pdfFile.getName().replace(".pdf", "");

        File destinationFile = new File(path);
        if (!destinationFile.exists()) {
            destinationFile.mkdir();
        }
        PDDocument document = PDDocument.load(pdfFile);
        PDPageTree list = document.getDocumentCatalog().getPages();
        int pageCounter = 0;
        for (PDPage page : list) {
            PDFRenderer pdfRenderer = new PDFRenderer(document);
            BufferedImage image = pdfRenderer.renderImageWithDPI(pageCounter, 100, ImageType.RGB);
            String target = path + fileName + "-" + (pageCounter++) + ".png";
            ImageIOUtil.writeImage(image, target, 100);

            w = image.getWidth();
            h += image.getHeight();
            images.add(image);
            new File(target).delete();
        }
        document.close();

        BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics g = combined.getGraphics();

        int y = 0;
        for (BufferedImage image : images) {
            g.drawImage(image, 0, y, null);
            y += image.getHeight();
        }

        // Save as new image
        File image = new File(path, fileName + ".png");
        ImageIO.write(combined, "PNG", image);
        return image;
    }

} 

自定义 ConverterDocument

import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
import com.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;
import com.sun.star.awt.Size;
import com.sun.star.beans.PropertyValue;
import com.sun.star.lang.XComponent;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.view.PaperFormat;
import com.sun.star.view.XPrintable;

public class ConverterDocument extends StreamOpenOfficeDocumentConverter {

    public ConverterDocument(OpenOfficeConnection connection) {
        super(connection);
    }

    public final static Size A5, A4, A3;
    public final static Size B4, B5, B6;
    public final static Size KaoqinReport;

    static {
        A5 = new Size(14800, 21000);
        A4 = new Size(21000, 29700);
        A3 = new Size(29700, 42000);

        B4 = new Size(25000, 35300);
        B5 = new Size(17600, 25000);
        B6 = new Size(12500, 17600);

//        KaoqinReport = new Size(29700, 27940);  //最大限度  宽 1600000
        KaoqinReport = new Size(25000, 21000);;
    }

    @Override
    protected void refreshDocument(XComponent document) {
        super.refreshDocument(document);

        // The default paper format and orientation is A4 and portrait. To
        // change paper orientation
        // re set page size
        XPrintable xPrintable = (XPrintable) UnoRuntime.queryInterface(XPrintable.class, document);
        PropertyValue[] printerDesc = new PropertyValue[2];

        // Paper Orientation
//  printerDesc[0] = new PropertyValue();
//  printerDesc[0].Name = "PaperOrientation";
//  printerDesc[0].Value = PaperOrientation.PORTRAIT;

        // Paper Format
        printerDesc[0] = new PropertyValue();
        printerDesc[0].Name = "PaperFormat";
        printerDesc[0].Value = PaperFormat.USER;

        // Paper Size
        printerDesc[1] = new PropertyValue();
        printerDesc[1].Name = "PaperSize";
        printerDesc[1].Value = KaoqinReport;

        try {
            xPrintable.setPrinter(printerDesc);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
} 

使用:

	public static void main(String[] args) throws Exception {
        OpenOfficeUtils.convert("D:\\test.xls", "D:\\test.pdf");
        pdf2image(new File("D:\\test.pdf"));
	}

参考: https://blog.csdn.net/liuhualiang/article/details/14094019?utm_source=blogxgwz6

到此这篇关于JAVA中使用openoffice将Excel转PDF再转图片功能实现的文章就介绍到这了,更多相关java openoffice Excel转PDF内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Java使用jacob将微软office中word、excel、ppt转成pdf

    本文实例为大家分享了Java使用jacob将微软office文档转成pdf的具体代码,供大家参考,具体内容如下 在使用jacb前,我们需要去下载 jacob.jar 和 jacob-1.18-x64.dll 其次,我们需要将jacob-1.18-x64.dll放入到jdk的bin目录下才可以使用 第三,使用jacb之前,我们需要确保office能正常使用 如果你现在使用的是maven工程,那么不好意思,现在还没有发布正式的jacb资源文件,我们需要自定的maven依赖,如下: <dependen

  • Java实现Word/Excel/TXT转PDF的方法

    引言: 前段时间公司做的教育系统,系统需要实时记录用户学习课程的情况和时间,所以对一些除视频课程之外,对一些文本文档型课件同样如此,初次的方案是讲office相关类型的文件进行转换Html文件,然后展示对应的html文件,PC端差不多没问题了,但是个别文件再转换html之后,样式出现了错乱,即时做了编码转换处理,但是还是有个别乱码,最后改变方案,最后统一将文件转为pdf,然后通过流的方式在前端展示,其中包括Word Excel PPT TXT PDF等文件,代码如下: 备注:本来是可以直接展示p

  • Java基于Spire Cloud Excel把Excel转换成PDF

    Spire.Cloud.Excel Sdk 提供GeneralApi接口和WorkbookApi接口,支持将本地Excel和云端Excel文档转换为ODS, PDF, XPS, PCL, PS等格式.本文以将Excel表格转为PDF为例,介绍实现格式转换的步骤及方法. 所需工具:Spire.Cloud.Excel.Sdk 必要步骤: 步骤1:Jar文件下载及导入.可通过"下载中心"下载获取jar:或者通过maven仓库安装导入,具体参考安装方法. 步骤2:ID及Key获取.需要在云端创

  • Java使用openOffice对于word的转换及遇到的问题解决

    一:需求详情: OpenOffice.org 是一套跨平台的办公室软件套件,能在 Windows.Linux.MacOS X (X11).和 Solaris 等操作系统上执行.它与各个主要的办公室软件套件兼容.OpenOffice.org 是自由软件,任何人都可以免费下载.使用.及推广它. 公司需要存储合同文件,用户上传word文档的合同,通过openOffice去把word转换为pdf.再把pdf转换为图片格式,并分别存储.因为openOffice的转换需要耗费挺大的内存,所以设计为task任

  • Java 使用openoffice进行word转换为pdf的方法步骤

    一.下载openoffice第三方工具 建议下载4.1.6版本 http://www.openoffice.org/download/index.html 二.开启openoffice服务 找到openoffice安装目录下OpenOffice 4\program>soffice运行cmd,运行命令soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard 三.Java代

  • JAVA中使用openoffice将Excel转PDF再转图片功能的实现代码

    需求 公司一个小项目要结尾了, 有非常多的表格, 而且非常复杂, 例如 例如:(这表格, 有想死的心-) 看到这样的表格,第一反应是n脸懵逼,这得做到啥时候啊,最后想到用一个方法,让客户自己玩!! 平台提供Excel模版下载,客户下载填写完再提交Excel,平台再将Excel转PDF,顺便将PDF转成图片,给前端展示,想法简单,方案可行,开工! 方案: windows server下用 jacob, windows上可完美运行, 但是!!!Linux上不支持jacob!!!(非常重要!!) po

  • java中两个字符串的拼接、整数相加和浮点数相加实现代码

    编写一个Java应用程序,从键盘读取用户输入两个字符串,并重载3个函数分别实现这两个字符串的拼接.整数相加和浮点数相加,并输出结果.要进行异常处理,对输入的不符合要求的字符串提示给用户 package zyy.wxt.demo; import java.util.Scanner; public class overload { public static void main(String[] args) { String s1 = null, s2 = null; Scanner sc = ne

  • Java中实现简单的Excel导出

    简单介绍一下Java中的Excel文件导出功能(基于HttpServletResponse实现下载) 首先,引入需要依赖的jar包: <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.14</version> </dependency> <dependency> <gro

  • C# 将Excel转为PDF时自定义表格纸张大小的代码思路

    通过后端程序将Excel表格转为PDF格式时,直接转换后的PDF效果可能出现表格页面过小或者过大,导致页面内容分布不均.要改善转换后的文档效果,只需在转换前自定义表格纸张大小,即可调整转换后的PDF页面表格布局效果.下面是具体方法和步骤. 引入dll 在Visual Studio中,打开"解决方案资源管理器",鼠标右键点击"引用", 1.通过NuGet安装dll(2种方法) 1.1 可以在Visual Studio中打开"解决方案资源管理器",鼠

  • vue实现pdf文件发送到邮箱功能的示例代码

    需求: vue实现pdf文件发送到邮箱功能 <!-- 弹窗 --> <van-popup v-model="showEmail" closeable class="contactTel" :close-on-click-overlay="false" @close="closeEmail"> <div class="popup-header fontSize36"> 发送

  • 在django项目中导出数据到excel文件并实现下载的功能

    依赖模块 xlwt下载:pip install xlwt 后台模块 view.py # 导出Excel文件 def export_excel(request): city = request.POST.get('city') print(city) list_obj=place.objects.filter(city=city) # 设置HTTPResponse的类型 response = HttpResponse(content_type='application/vnd.ms-excel')

  • python中使用 xlwt 操作excel的常见方法与问题

    前言 Python可以操作Excel的模块不止一种,我习惯使用的写入模块是xlwt(一般都是读写模块分开的) python中使用xlwt操作excel非常方,和Java使用调框架apache poi相比这就是天堂啊,下面话不多说了,来一起看看详细的介绍吧 一.安装xlwt模块 pip3 install xlwt 二.简单使用xlwt import xlwt #导入模块 workbook = xlwt.Workbook(encoding='utf-8') #创建workbook 对象 worksh

  • 详解Java如何实现百万数据excel导出功能

    目录 前言 1.异步处理 1.1 使用job 1.2 使用mq 2.使用easyexcel 3.分页查询 4.多个sheet 5.计算limit的起始位置 6.文件上传到OSS 7.通过WebSocket推送通知 8.总条数可配置 9.order by商品编号 总结 前言 最近我做过一个MySQL百万级别数据的excel导出功能,已经正常上线使用了. 这个功能挺有意思的,里面需要注意的细节还真不少,现在拿出来跟大家分享一下,希望对你会有所帮助. 原始需求:用户在UI界面上点击全部导出按钮,就能导

  • java 中使用匿名类直接new接口详解及实例代码

    java:使用匿名类直接new接口 java中的匿名类有一个倍儿神奇的用法,见下面代码示例: package contract; public interface ISay { void sayHello(); } 上面是一个简单的接口,下面是如何使用: package jimmy; import contract.ISay; public class Program { public static void main(String[] args) { ISay say = new ISay()

  • java中加密的实现方法(MD5,MD2,SHA)

    java中加密的实现方法(MD5,MD2,SHA) 实例代码:注释都很清楚, import java.security.MessageDigest; import javax.xml.bind.annotation.adapters.HexBinaryAdapter; public class Main { static String src = "Hello,sahadev!"; public static void main(String[] args) { MD5(); MD2(

随机推荐