java
String projectPath = System.getProperty("user.dir");
File file = new File(projectPath + "/filename");
获取项目使用路径,在其下面创建一个文件夹俩存放内容、
javaString unzipPath=RecMrDetailIndexController.class.getResource("/unzip/").getPath();
在项目resources目录下先创建一个文件夹,存放一些文件,打包时会打进targer-classes目录下面,可以直接在classes下找到自己创建的文件夹,将文件存放到里面
先读取压缩文件到本地,然后解压,再向前端输出文件夹中的内容
这部分忽略,可以直接查看之前的文章,直接从ftpUtil获取文件,得到ByteArrayOutputStream开始,讲解
java
//通过zip获取pdf
public ByteArrayOutputStream getPdfBase64ByZip(ByteArrayOutputStream fileData,String fileName) throws Exception {
ByteArrayInputStream inputStream = new ByteArrayInputStream(fileData.toByteArray());
String base64= Base64Encoder.encode(IOUtils.toByteArray(inputStream));
System.out.println(base64);
String unzipPath=RecMrDetailIndexController.class.getResource("/unzip/").getPath();
String zipName=unzipPath+fileName.split("as")[0]+"zip";
FileUtils.base64ToFile(zipName,base64);
ZipUtil.unZip(zipName,unzipPath,"mars");
String pdfName=unzipPath+fileName.split("as")[0]+"pdf";
System.out.println("pdfName"+pdfName);
File file=new File(pdfName);
FileInputStream fileInputStream=new FileInputStream(file);
byte[] bytes=IOUtils.toByteArray(fileInputStream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(bytes.length);
outputStream.write(bytes, 0, bytes.length);
return outputStream;
}
业务需要将ftp文件压缩加密并且转存,先读取ftp源文件再写入临时目录,然后在临时文件中加密压缩,再通过ftp上传,清除临时目录中的文件
java
public String getPdfByFtpUrl(RecTypeDictStorageEntity storageEntity,ViewArchiveDocumentsEntity viewArchiveDocuments) {
ByteArrayOutputStream fileData=new ByteArrayOutputStream();
FtpUtil ftpUtil = new FtpUtil();
String ftpConfig = "ftp://USER:PWD@IP:PORT";
ftpConfig = ftpConfig.replace("IP", storageEntity.getFtpIp())
.replace("USER", storageEntity.getFtpUser())
.replace("PWD", storageEntity.getFtpPwd())
.replace("PORT", storageEntity.getFtpPort());
ftpUtil.getConn(ftpConfig);
String remoteFile = viewArchiveDocuments.getDocfile().substring(0, viewArchiveDocuments.getDocfile().lastIndexOf("/") + 1);
String fileName = viewArchiveDocuments.getDocfile().substring(viewArchiveDocuments.getDocfile().lastIndexOf("/") + 1);
try {
boolean result = ftpUtil.fileExist(remoteFile, fileName);
if (result) {
fileData = ftpUtil.fileGet(remoteFile, fileName);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ftpUtil.ftpDisconnect();
}
if (fileData!=null) {
try {
byte[] fileArray=fileData.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(fileArray);
return Base64.getEncoder().encodeToString(IOUtils.toByteArray(inputStream));
} catch (Exception ex) {
logger.info(ex.getMessage());
return "";
}
}
logger.info("找不到文件,获取不了文件信息");
return "";
}
java byte[] bytes = Base64.getDecoder().decode(base64Str);
改成
javabyte[] bytes = Base64.getMimeDecoder().decode(base64Str);
hanlp官网,HanLP 是由一系列模型与算法组成的工具包,目标是普及自然语言处理在生产环境中的应用。HanLP 具备功能完善、性能高效、架构清晰、语料时新、可自定义的特点。
HanLP 主要功能包括分词、词性标注、关键词提取、自动摘要、依存句法分析、命名实体识别、短语提取、拼音转换、简繁转换等等。
xml
<dependency>
<groupId>com.hankcs</groupId>
<artifactId>hanlp</artifactId>
<version>portable-1.7.3</version>
</dependency>