当前位置: 首页 > news >正文

新建网站/seo是怎么优化

新建网站,seo是怎么优化,做网站时候图片和视频放在哪里,超炫网站页面1:新建 ZipUtils 工具类 package com.ly.cloud.datacollection.util;import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URLEncoder; import ja…

1:新建 ZipUtils 工具类

package com.ly.cloud.datacollection.util;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;@Slf4j
public class ZipUtils {private static final int BUFFER_SIZE = 10 * 1024;/*** * @param fileList 多文件列表* @param zipPath 压缩文件临时目录* @return*/public static Boolean zipFiles(List<File> fileList, File zipPath) {boolean flag = true;// 1 文件压缩if (!zipPath.exists()) { // 判断压缩后的文件存在不,不存在则创建try {zipPath.createNewFile();} catch (IOException e) {flag=false;e.printStackTrace();}}FileOutputStream fileOutputStream=null;ZipOutputStream zipOutputStream=null;FileInputStream fileInputStream=null;try {fileOutputStream=new FileOutputStream(zipPath); // 实例化 FileOutputStream对象zipOutputStream=new ZipOutputStream(fileOutputStream); // 实例化 ZipOutputStream对象ZipEntry zipEntry=null; // 创建 ZipEntry对象for (int i=0; i<fileList.size(); i++) { // 遍历源文件数组fileInputStream = new FileInputStream(fileList.get(i)); // 将源文件数组中的当前文件读入FileInputStream流中zipEntry = new ZipEntry("("+i+")"+fileList.get(i).getName()); // 实例化ZipEntry对象,源文件数组中的当前文件zipOutputStream.putNextEntry(zipEntry);int len; // 该变量记录每次真正读的字节个数byte[] buffer=new byte[BUFFER_SIZE]; // 定义每次读取的字节数组while ((len=fileInputStream.read(buffer)) != -1) {zipOutputStream.write(buffer, 0, len);}}zipOutputStream.closeEntry();zipOutputStream.close();fileInputStream.close();fileOutputStream.close();} catch (IOException e) {flag=false;e.printStackTrace();} finally {try {  fileInputStream.close();zipOutputStream.close();fileOutputStream.close();} catch (Exception e){flag=false;e.printStackTrace();}}return flag;}/*** @param srcDir           压缩文件夹路径* @param keepDirStructure 是否保留原来的目录结构,*                         true:保留目录结构;*                         false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)* @param response * @throws RuntimeException 压缩失败会抛出运行时异常*/public static void toZip(String[] srcDir, String outDir,boolean keepDirStructure, HttpServletResponse response) throws RuntimeException, Exception {// 设置输出的格式response.reset();response.setContentType("bin");outDir = URLEncoder.encode(outDir,"UTF-8");response.addHeader("Content-Disposition","attachment;filename=" + outDir);OutputStream out = response.getOutputStream();response.setContentType("application/octet-stream");ZipOutputStream zos = null;try {zos = new ZipOutputStream(out);List<File> sourceFileList = new ArrayList<File>();for (String dir : srcDir) {File sourceFile = new File(dir);sourceFileList.add(sourceFile);}compress(sourceFileList, zos, keepDirStructure);} catch (Exception e) {throw new RuntimeException("zip error from ZipUtils", e);} finally {if (zos != null) {try {zos.close();out.close();} catch (IOException e) {e.printStackTrace();}}}}/*** @param srcDir           压缩文件夹路径* @param keepDirStructure 是否保留原来的目录结构,*                         true:保留目录结构;*                         false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)* @param response * @throws RuntimeException 压缩失败会抛出运行时异常*/public static void toZip(String[] srcDir, String outDir,boolean keepDirStructure) throws RuntimeException, Exception {// 设置输出的格式//outDir = URLEncoder.encode(outDir,"UTF-8");long start= System.currentTimeMillis();FileOutputStream out=null;ZipOutputStream zos = null;try {out=new FileOutputStream(outDir); // 实例化 FileOutputStream对象zos = new ZipOutputStream(out);List<File> sourceFileList = new ArrayList<File>();for (String dir : srcDir) {File sourceFile = new File(dir);sourceFileList.add(sourceFile);}compress(sourceFileList, zos, keepDirStructure);} catch (Exception e) {throw new RuntimeException("zip error from ZipUtils", e);} finally {if (zos != null) {try {zos.close();out.close();log.info(outDir+"压缩完成");printInfo(start);} catch (IOException e) {e.printStackTrace();}}}}/*** 递归压缩方法** @param sourceFile       源文件* @param zos              zip输出流* @param name             压缩后的名称* @param keepDirStructure 是否保留原来的目录结构,*                         true:保留目录结构;*                         false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)* @throws Exception 异常*/private static void compress(File sourceFile, ZipOutputStream zos,String name, boolean keepDirStructure) throws Exception {byte[] buf = new byte[BUFFER_SIZE];recursion(sourceFile, zos, name, keepDirStructure, buf);}/**** @param sourceFileList    源文件列表* @param zos               zip输出流* @param keepDirStructure  是否保留原来的目录结构,*                          true:保留目录结构;*                          false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)* @throws Exception        异常*/private static void compress(List<File> sourceFileList,ZipOutputStream zos, boolean keepDirStructure) throws Exception {byte[] buf = new byte[BUFFER_SIZE];for (File sourceFile : sourceFileList) {String name = sourceFile.getName();recursion(sourceFile, zos, name, keepDirStructure, buf);}}/**** @param sourceFile       源文件* @param zos              zip输出流* @param name             文件名* @param keepDirStructure 否保留原来的目录结构,*                         true:保留目录结构;*                         false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)* @param buf              字节数组* @throws Exception       异常*/private static void recursion(File sourceFile, ZipOutputStream zos, String name, boolean keepDirStructure, byte[] buf) {if (sourceFile.isFile()) {FileInputStream in=null;try {in = new FileInputStream(sourceFile);zos.putNextEntry(new ZipEntry(name));int len;while ((len = in.read(buf)) != -1) {zos.write(buf, 0, len);}zos.closeEntry();in.close();} catch (IOException e) {e.printStackTrace();}finally {try {in.close();} catch (IOException e) {e.printStackTrace();}}} else {File[] listFiles = sourceFile.listFiles();if (listFiles == null || listFiles.length == 0) {if (keepDirStructure) {try {zos.putNextEntry(new ZipEntry(name + "/"));zos.closeEntry();} catch (IOException e) {e.printStackTrace();}}} else {for (File file : listFiles) {if (keepDirStructure) {try {compress(file, zos, name + "/" + file.getName(),true);} catch (Exception e) {e.printStackTrace();}} else {try {compress(file, zos, file.getName(), false);} catch (Exception e) {e.printStackTrace();}}}}}}public static int deleteFile(File file) {//判断是否存在此文件int count=0;if (file.exists()) {//判断是否是文件夹if (file.isDirectory()) {File[] files = file.listFiles();//判断文件夹里是否有文件if (files.length >= 1) {//遍历文件夹里所有子文件for (File file1 : files) {//是文件,直接删除if (file1.isFile()) {count++;file1.delete();} else {//是文件夹,递归count++;deleteFile(file1);}}//file此时已经是空文件夹file.delete();} else {//是空文件夹,直接删除file.delete();}} else {//是文件,直接删除file.delete();}} else {}return count;}public static void downloadFile(String path, File file, String outDir, HttpServletResponse response){OutputStream os = null;FileInputStream fis=null;try {fis = new FileInputStream(file);// 取得输出流os = response.getOutputStream();//String contentType = Files.probeContentType(Paths.get(file.getAbsolutePath()));outDir = URLEncoder.encode(outDir,"UTF-8");response.addHeader("Content-Disposition","attachment;filename=" + outDir);response.setContentType("application/octet-stream");response.setHeader("Content-Length", String.valueOf(file.length()));//response.setHeader("Content-Disposition", "attachment;filename="+ outDir);//response.setHeader("Content-Disposition", "attachment;filename="+ new String(file.getName().getBytes("utf-8"),"ISO8859-1"));/** int len; // 该变量记录每次真正读的字节个数 byte[] buffer=new byte[BUFFER_SIZE]; //* 定义每次读取的字节数组 while ((len=fis.read(buffer)) != -1) { os.write(buffer, 0, len);* }*/WritableByteChannel writableByteChannel = Channels.newChannel(os);FileChannel fileChannel = fis.getChannel();ByteBuffer buffer=ByteBuffer.allocate(BUFFER_SIZE);long total=0L;int len=0;while((len=fileChannel.read(buffer))!=-1){total=total+len;buffer.flip();// 保证缓冲区的数据全部写入while (buffer.hasRemaining()){writableByteChannel.write(buffer);}buffer.clear();}log.info(outDir+"下载完成");os.flush();fileChannel.close();writableByteChannel.close();} catch (IOException e) {e.printStackTrace();}//文件的关闭放在finally中finally {try {if (fis != null) {fis.close();}if (os != null) {os.flush();os.close();}} catch (IOException e) {e.printStackTrace();}}}public static void printInfo(long beginTime) {long endTime = System.currentTimeMillis();long total = endTime - beginTime;log.info("压缩耗时:" + total / 1000 + "秒");}
}

2:简单测试

    @GetMapping(value = "/zip")@AnonymityAnnotation(access = true)public WebResponse<String> zip(@RequestParam("file") MultipartFile file) throws IOException {InputStream stream = file.getInputStream();System.out.println(stream);//下载压缩后的地址String path = "D:/91-69ddf076d28040d29e59aec22b65b150";//获取文件原本的名称String fileName = file.getOriginalFilename();System.out.println(fileName);String[] src = { path + "/" + fileName };String outDir = path + "/69.zip";try {ZipUtils.toZip(src, outDir, true);} catch (Exception e) {}return new WebResponse<String>().success("OK");}

3:效果图

相关文章:

Java代码如何对Excel文件进行zip压缩

1&#xff1a;新建 ZipUtils 工具类 package com.ly.cloud.datacollection.util;import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URLEncoder; import ja…...

改进YOLO系列:12.Repulsion损失函数【遮挡】

1. RepLoss论文 物体遮挡问题可以分为类内遮挡和类间遮挡两种情况。类间遮挡产生于扎堆的同类物体,也被称为密集遮挡(crowd occlusion)。Repulsion损失函数由三个部分构成,yolov5样本匹配,得到的目标框和预测框-一对应第一部分主要作用:预测目标框吸引IOU最大的真实目标框,…...

win11网络连接正常,但是无法正常上网

前言&#xff1a; 这个是一个win11的bug&#xff0c;好多人都遇到了&#xff0c;在孜孜不倦的百度下&#xff0c;毫无收获&#xff0c;终于是在抖音上看到有人分享的经验而解决了这个问题。 找到internet选项&#xff0c;然后点击打开 选择连接 将代理服务器中&#xff0c;为…...

硬科技企业社区“曲率引擎”品牌正式发布

“曲率引擎”&#xff0c;是科幻作品中最硬核的加速系统&#xff0c;通过改变时空的曲率&#xff0c;可实现光速飞行甚至能够超越光速。11月3日&#xff0c;“曲率引擎&#xff08;warp drive&#xff09;”作为硬科技企业社区品牌&#xff0c;在2023全球硬科技创新大会上正式对…...

少儿编程 2023年9月中国电子学会图形化编程等级考试Scratch编程三级真题解析(判断题)

2023年9月scratch编程等级考试三级真题 判断题(共10题,每题2分,共20分) 19、运行程序后,“我的变量”的值为25 答案:对 考点分析:考查积木综合使用,重点考查变量和运算积木的使用 开始我的变量为50,执行完第二行代码我的变量变为49,条件不成立执行否则语句,所以…...

MCU常见通信总线串讲(二)—— RS232和RS485

&#x1f64c;秋名山码民的主页 &#x1f602;oi退役选手&#xff0c;Java、大数据、单片机、IoT均有所涉猎&#xff0c;热爱技术&#xff0c;技术无罪 &#x1f389;欢迎关注&#x1f50e;点赞&#x1f44d;收藏⭐️留言&#x1f4dd; 获取源码&#xff0c;添加WX 目录 前言一…...

LazyVim: 将 Neovim 升级为完整 IDE | 开源日报 No.67

curl/curl Stars: 31.5k License: NOASSERTION Curl 是一个命令行工具&#xff0c;用于通过 URL 语法传输数据。 核心优势和关键特点包括&#xff1a; 可在命令行中方便地进行数据传输支持多种协议 (HTTP、FTP 等)提供丰富的选项和参数来满足不同需求 kubernetes/ingress-n…...

想要搭建网站帮助中心,看这一篇指南就对了!

在现今互联网时代&#xff0c;除了让用户了解产品的功能和一些操作&#xff0c;很多企业都需要在网上进行信息的发布和产品销售等业务活动。而这就需要一个帮助中心&#xff0c;在用户遇到问题或者需要了解更多信息的时候&#xff0c;能够快速地解答他们的疑惑和提供响应的帮助…...

92.更新一些收藏的经验贴总结学习

一、JS相关 1.进制转换 &#xff08;1&#xff09;十进制转二进制 十进制数除2取余法&#xff1a;十进制数除2&#xff0c;余数为权位上的数&#xff0c;得到的商继续除2&#xff0c;直到商为0。最后余数从下往上取值。 &#xff08;2&#xff09;二进制转十进制 把二进制…...

mysql 问题解决 4

7、集群 7.1 日志 1、MySQL 中有哪些常见日志? MySQL 中有以下常见的日志类型: 错误日志(Error Log):记录 MySQL 服务器在运行过程中出现的错误信息。通用查询日志(General Query Log):记录所有连接到 MySQL 服务器的 SQL 查询语句。慢查询日志(Slow Query Log):…...

llama-7B、vicuna-7b-delta-v1.1和vicuna-7b-v1.3——使用体验

Chatgpt的出现给NLP领域带来了让人振奋的消息&#xff0c;可以很逼真的模拟人的对话&#xff0c;回答人们提出的问题&#xff0c;不过Chatgpt参数量&#xff0c;规模&#xff0c;训练代价都很昂贵。 幸运的是&#xff0c;出现了开源的一些相对小的模型&#xff0c;可以在本地或…...

深入理解JVM虚拟机第十九篇:JVM字节码中方法内部的结构和与局部变量表中变量槽的介绍

大神链接:作者有幸结识技术大神孙哥为好友,获益匪浅。现在把孙哥视频分享给大家。 孙哥链接:孙哥个人主页 作者简介:一个颜值99分,只比孙哥差一点的程序员 本专栏简介:话不多说,让我们一起干翻JVM 本文章简介:话不多说,让我们讲清楚虚拟机栈存储结构和运行原理 文章目…...

windows好玩的cmd命令

颜色 后边的数字查表吧,反正我是喜欢一个随机的数字 color 01MAC getmac /v更新主机IP地址 通过DHCP更新 ipconfig /release ipconfig /renew改标题 title code with 你想要的标题...

线扫相机DALSA--常见问题四:修改相机参数,参数保存无效情况

该问题是操作不当&#xff0c;未按照正常步骤保存参数所致&#xff0c;相机为RAM机制&#xff0c;参数需保存在采集卡的ROM内。 保存参数步骤&#xff1a; ①首先将相机参数保存至User Set1&#xff1b; ②然后回到Board(采集卡)参数设置区&#xff0c;鼠标选中Basic Timing&a…...

linux中用date命令获取昨天、明天或多天前后的日期

在实际操作中&#xff0c;一些脚本中会调用明天&#xff0c;或者昨天&#xff0c;或更多天前的日期&#xff0c;本文将叙述讲述用date命令实现时间的显示。在Linux系统中用man date -d 查询的参数说的比较模糊&#xff0c;以下举例进一步说明&#xff1a; # man date -d, --da…...

【无标题】360压缩软件怎么用?超级好用!

360压缩是一款功能强大的解压缩软件&#xff0c;如何用它压缩文件呢&#xff1f;下面给出了详细的操作步骤。 一、360压缩详细步骤 1、下载软件后&#xff0c;在电脑上右击需要压缩的文件&#xff0c;在弹出的菜单中点击【添加到压缩文件】选项。 2、在360压缩窗口中按需设置相…...

一图搞懂傅里叶变换(FT)、DTFT、DFS和DFT之间的关系

自然界中的信号都是模拟信号&#xff0c;计算机无法处理&#xff0c;因此我们会基于奈奎斯特定理对模拟信号采样得到数字信号。 但是我们发现&#xff0c;即便是经过采样&#xff0c;在时域上得到了数字信号&#xff0c;而在频域上还是连续信号。 因此我们可以在时域中选取N点…...

行情分析——加密货币市场大盘走势(11.7)

大饼昨日下跌过后开始有回调的迹象&#xff0c;现在还是在做指标修复&#xff0c;大饼的策略保持逢低做多。稳健的依然是不碰&#xff0c;目前涨不上去&#xff0c;跌不下来。 以太昨天给的策略&#xff0c;依然有效&#xff0c;现在以太坊开始回调。 目前来看&#xff0c;回踩…...

阿里微服务质量保障系列:故障演练

对于很多大型企业(如阿里巴巴)来说,经过多年的技术演进,系统工具和架构已经高度垂直化,服务器规模也达到了比较大的体量。当服务规模大于一定量(如10000台)时,小概率的硬件故障每天都会发生。这时如果需要人的干预,系统就无法可靠的伸缩。 为此每一层的系统都会面向失…...

基于springboot+vue开发的教师工作量管理系

教师工作量管理系 springboot31 源码合集&#xff1a;www.yuque.com/mick-hanyi/javaweb 源码下载&#xff1a;博主私 摘要 随着信息技术在管理上越来越深入而广泛的应用&#xff0c;管理信息系统的实施在技术上已逐步成熟。本文介绍了教师工作量管理系统的开发全过程。通过…...

【NI-DAQmx入门】NI-DAQmx之C、C++、VB、VB.net与C#支持

DAQmx应用程序编程接口(API) DAQmx附带数据采集编程所需的API。DAQmx API只是一组库&#xff0c;其中包含关于如何执行所有数据采集操作的函数。这些API支持LabWindows/CVI、C、C、Visual Basic 6.0、VB.NET和C#。 DAQmx API随DAQmx驱动程序一起安装&#xff0c;包含以下参考…...

python转xml为json

以下代码取自获取PA防火墙策略XML文件并转为JSON文件的场景&#xff1a; 通过PA防火墙API获取防火墙策略 防火墙策略xpath为./result/security/rules/entry 以下代码实现将所有entry即策略与策略相关属性转为json对象并存储至文件 import xml.etree.ElementTree as ET import …...

PHP Curl请求封装

php 中curl请求模块封装 <?php namespace App\Utils;/*** http 工具类* author Administrator**/ class HttpUtils {private static $_instance;private function __construct(){}public static function getInstance(){if( null self::$_instance ){self::$_instance n…...

java list set 特性

List的常用实现类 ArrayList (常用) JDK1.2 底层数组实现 查询快,增删慢 线程不安全,效率高 LinkedList JDK1.2 底层链表实现 查询慢,增删快 线程不安全,效率高 Vector JDK1.0 底层数组实现 都慢 线程安全,效率低 List 集合名new 实现类(); 常用方法 集合名.方法名(实参列表…...

Docker 用centos 编译安装apache

Docker 用centos 编译安装apache 前提条件&#xff1a; 安装docker 如果想安装docker请查阅&#xff1a;安装docker 环境准备&#xff1a;centos8 拉取centos镜像 [rootlvs docker]# docker pull centos:8 8: Pulling from library/centos a1d0c7532777: Pull complete Di…...

专访虚拟人科技:如何利用 3DCAT 实时云渲染打造元宇宙空间

自古以来&#xff0c;人们对理想世界的探索从未停止&#xff0c;而最近元宇宙的热潮加速了这一步伐&#xff0c;带来了许多新的应用。作为元宇宙的关键入口&#xff0c;虚拟现实&#xff08;VR&#xff09;将成为连接虚拟和现实的桥梁。苹果发布的VISION PRO头戴设备将人们对VR…...

第三章:人工智能深度学习教程-基础神经网络(第二节-ANN 和 BNN 的区别)

在本文中&#xff0c;我们将了解单层感知器及其使用 TensorFlow 库在Python中的实现。神经网络的工作方式与我们的生物神经元的工作方式相同。 生物神经元的结构 生物神经元具有三个基本功能 接收外部信号。 处理信号并增强是否需要发送信息。 将信号传递给目标细胞&#x…...

回归模型原理总结及代码实现

前言 本文将介绍回归模型算法&#xff0c;并总结了一些常用的除线性回归模型之外的模型&#xff0c;其中包括一些单模型及集成学习器。 保序回归、多项式回归、多输出回归、多输出K近邻回归、决策树回归、多输出决策树回归、AdaBoost回归、梯度提升决策树回归、人工神经网络、…...

游戏开发中的“御用中介“

点击上方亿元程序员关注和★星标 引言 大家好&#xff0c;我是亿元程序员&#xff0c;一位有着8年游戏行业经验的主程。 本系列是《和8年游戏主程一起学习设计模式》&#xff0c;让糟糕的代码在潜移默化中升华&#xff0c;欢迎大家关注分享收藏订阅。 游戏开发中的"御用…...

flink1.15报错 processElement_split

flink sql 完整报错 Caused by: java.lang.NullPointerExceptionat StreamExecCalc$1148.processElement_split178(Unknown Source) ~[?:?]at StreamExecCalc$1148.processElement(Unknown Source) ~[?:?]at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutp…...