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

乡镇政府可以做网站认好的推广平台

乡镇政府可以做网站认,好的推广平台,在线做爰a视频网站,建筑网站的研究背景与意义工具类如下 打包下载方法:exportZip(支持整个文件夹或单文件一起) 注意:前端发送请求不能用ajax,form表单提交可以,location.href也可以,window.open也可以,总之就ajax请求就是不行 import com.…

工具类如下
打包下载方法:exportZip(支持整个文件夹或单文件一起)
注意:前端发送请求不能用ajax,form表单提交可以,location.href也可以,window.open也可以,总之就ajax请求就是不行

import com.leatop.common.utils.StringUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;public class FileToZipUtils {// 日志private static Logger log = LoggerFactory.getLogger(FileToZipUtils.class);// 创建文件夹public static String CreateFile(String dir) {File file = new File(dir);if (!file.exists()) {//创建文件夹boolean mkdir = file.mkdir();} else {}return dir;}// 复制文件public static void copyFile(File source, File dest) throws IOException {FileChannel inputChannel = null;FileChannel outputChannel = null;try {inputChannel = new FileInputStream(source).getChannel();outputChannel = new FileOutputStream(dest).getChannel();outputChannel.transferFrom(inputChannel, 0, inputChannel.size());} finally {inputChannel.close();outputChannel.close();}}// 删除文件public void delFile(File file) {File[] listFiles = file.listFiles();if (listFiles != null) {for (File f : listFiles) {if (f.isDirectory()) {delFile(f);} else {f.delete();}}}file.delete();}/*** 通过递归逐层删除文件信息** @param filePath*/public static void deleteFileByIO(String filePath) {File file = new File(filePath);File[] list = file.listFiles();if (list != null) {for (File temp : list) {deleteFileByIO(temp.getAbsolutePath());}}file.delete();}/*** 将指定路径下的所有文件打包zip导出** @param response       HttpServletResponse* @param sourceFilePath 要打包的路径* @param fileName       下载时的文件名称*                       //     * @param postfix 下载时的文件后缀 .zip/.rar*/public static void exportZip(HttpServletResponse response, String sourceFilePath, String fileName) {// 默认文件名以时间戳作为前缀SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");String downloadName = sdf.format(new Date()) + fileName;// 将文件进行打包下载try {OutputStream os = response.getOutputStream();// 接收压缩包字节byte[] data = createZip(sourceFilePath);response.reset();response.setCharacterEncoding("UTF-8");response.addHeader("Access-Control-Allow-Origin", "*");response.setHeader("Access-Control-Expose-Headers", "*");// 下载文件名乱码问题response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));//response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);response.addHeader("Content-Length", "" + data.length);response.setContentType("application/octet-stream;charset=UTF-8");IOUtils.write(data, os);os.flush();os.close();} catch (Exception e) {e.printStackTrace();}}/**** 压缩文件变成zip输出流*/public static byte[] createZip(String srcSource) throws Exception {ByteArrayOutputStream outputStream = new ByteArrayOutputStream();ZipOutputStream zip = new ZipOutputStream(outputStream);//将目标文件打包成zip导出File file = new File(srcSource);createAllFile(zip, file, "");IOUtils.closeQuietly(zip);return outputStream.toByteArray();}/**** 对文件下的文件处理*/public static void createAllFile(ZipOutputStream zip, File file, String dir) throws Exception {//如果当前的是文件夹,则进行进一步处理if (file.isDirectory()) {//得到文件列表信息File[] files = file.listFiles();//将文件夹添加到下一级打包目录zip.putNextEntry(new ZipEntry(dir + "/"));dir = dir.length() == 0 ? "" : dir + "/";//循环将文件夹中的文件打包for (int i = 0; i < files.length; i++) {createAllFile(zip, files[i], dir + files[i].getName());                 //递归处理}} else {     //当前的是文件,打包处理//文件输入流BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));ZipEntry entry = new ZipEntry(dir);zip.putNextEntry(entry);zip.write(FileUtils.readFileToByteArray(file));IOUtils.closeQuietly(bis);zip.flush();zip.closeEntry();}}/*** 将存放在sourceFilePath目录下的源文件,打包成fileName名称的zip文件,并存放到zipFilePath路径下** @param sourceFilePath :待压缩的文件路径* @param zipFilePath    :压缩后存放路径* @param fileName       :压缩后文件的名称* @return*/public static boolean fileToZip(String sourceFilePath, String zipFilePath, String fileName) {boolean flag = false;File sourceFile = new File(sourceFilePath);FileInputStream fis = null;BufferedInputStream bis = null;FileOutputStream fos = null;ZipOutputStream zos = null;if (sourceFile.exists() == false) {log.info("待压缩的文件目录:" + sourceFilePath + "不存在.");} else {try {File zipFile = new File(zipFilePath + "/" + fileName + ".zip");if (zipFile.exists()) {log.info(zipFilePath + "目录下存在名字为:" + fileName + ".zip" + "打包文件.");} else {File[] sourceFiles = sourceFile.listFiles();if (null == sourceFiles || sourceFiles.length < 1) {log.info("待压缩的文件目录:" + sourceFilePath + "里面不存在文件,无需压缩.");} else {fos = new FileOutputStream(zipFile);zos = new ZipOutputStream(new BufferedOutputStream(fos));byte[] bufs = new byte[1024 * 10];for (int i = 0; i < sourceFiles.length; i++) {// 创建ZIP实体,并添加进压缩包ZipEntry zipEntry = new ZipEntry(sourceFiles[i].getName());zos.putNextEntry(zipEntry);// 读取待压缩的文件并写进压缩包里fis = new FileInputStream(sourceFiles[i]);bis = new BufferedInputStream(fis, 1024 * 10);int read = 0;while ((read = bis.read(bufs, 0, 1024 * 10)) != -1) {zos.write(bufs, 0, read);}}flag = true;}}} catch (FileNotFoundException e) {e.printStackTrace();throw new RuntimeException(e);} catch (IOException e) {e.printStackTrace();throw new RuntimeException(e);} finally {// 关闭流try {if (null != bis)bis.close();if (null != zos)zos.close();} catch (IOException e) {e.printStackTrace();throw new RuntimeException(e);}}}return flag;}/*** 解压缩zip包** @param zipFilePath        需要解压的zip文件的全路径* @param unzipFilePath      解压后的文件保存的路径* @param includeZipFileName 解压后的文件保存的路径是否包含压缩文件的文件名。true-包含;false-不包含*/@SuppressWarnings("unchecked")public static void unzip(String zipFilePath, String unzipFilePath, boolean includeZipFileName) throws Exception {if (StringUtils.isNotBlank(zipFilePath) || StringUtils.isNotBlank(unzipFilePath)) {File zipFile = new File(zipFilePath);// 如果解压后的文件保存路径包含压缩文件的文件名,则追加该文件名到解压路径if (includeZipFileName) {String fileName = zipFile.getName();if (StringUtils.isNotEmpty(fileName)) {fileName = fileName.substring(0, fileName.lastIndexOf("."));}unzipFilePath = unzipFilePath + File.separator + fileName;}// 创建解压缩文件保存的路径File unzipFileDir = new File(unzipFilePath);if (!unzipFileDir.exists() || !unzipFileDir.isDirectory()) {unzipFileDir.mkdirs();}                        // 开始解压ZipEntry entry = null;String entryFilePath = null, entryDirPath = null;File entryFile = null, entryDir = null;int index = 0, count = 0, bufferSize = 1024;byte[] buffer = new byte[bufferSize];BufferedInputStream bis = null;BufferedOutputStream bos = null;ZipFile zip = new ZipFile(zipFile);Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zip.entries();// 循环对压缩包里的每一个文件进行解压while (entries.hasMoreElements()) {entry = entries.nextElement();// 构建压缩包中一个文件解压后保存的文件全路径entryFilePath = unzipFilePath + File.separator + entry.getName();// 构建解压后保存的文件夹路径index = entryFilePath.lastIndexOf(File.separator);if (index != -1) {entryDirPath = entryFilePath.substring(0, index);} else {entryDirPath = "";}entryDir = new File(entryDirPath);// 如果文件夹路径不存在,则创建文件夹if (!entryDir.exists() || !entryDir.isDirectory()) {entryDir.mkdirs();}                                // 创建解压文件entryFile = new File(entryFilePath);if (entryFile.exists()) {// 检测文件是否允许删除,如果不允许删除,将会抛出SecurityExceptionSecurityManager securityManager = new SecurityManager();securityManager.checkDelete(entryFilePath);// 删除已存在的目标文件entryFile.delete();}                                // 写入文件bos = new BufferedOutputStream(new FileOutputStream(entryFile));bis = new BufferedInputStream(zip.getInputStream(entry));while ((count = bis.read(buffer, 0, bufferSize)) != -1) {bos.write(buffer, 0, count);}bos.flush();bos.close();}zip.close();// 切记一定要关闭掉,不然在同一个线程,你想解压到临时路径之后,再去删除掉这些临时数据,那么就删除不了}}}

文章转载自:
http://digressive.c7501.cn
http://luganda.c7501.cn
http://discardable.c7501.cn
http://nonprovided.c7501.cn
http://instantaneous.c7501.cn
http://wolfling.c7501.cn
http://herpetologist.c7501.cn
http://lacerant.c7501.cn
http://posting.c7501.cn
http://fictionist.c7501.cn
http://danite.c7501.cn
http://isolog.c7501.cn
http://bike.c7501.cn
http://colostomy.c7501.cn
http://recoronation.c7501.cn
http://feldspathic.c7501.cn
http://frondage.c7501.cn
http://caconym.c7501.cn
http://sensibilia.c7501.cn
http://cecrops.c7501.cn
http://operose.c7501.cn
http://whereunder.c7501.cn
http://annoying.c7501.cn
http://epitaxy.c7501.cn
http://shf.c7501.cn
http://sideroscope.c7501.cn
http://holdover.c7501.cn
http://uncomplimentary.c7501.cn
http://scopophilia.c7501.cn
http://hamam.c7501.cn
http://korinthos.c7501.cn
http://teacup.c7501.cn
http://enchase.c7501.cn
http://qiviut.c7501.cn
http://immalleable.c7501.cn
http://spite.c7501.cn
http://gorm.c7501.cn
http://koei.c7501.cn
http://impar.c7501.cn
http://argumental.c7501.cn
http://yahwism.c7501.cn
http://lockmaker.c7501.cn
http://incense.c7501.cn
http://gosain.c7501.cn
http://problemist.c7501.cn
http://neatly.c7501.cn
http://cachucha.c7501.cn
http://schmoe.c7501.cn
http://mesothelioma.c7501.cn
http://ced.c7501.cn
http://dysbarism.c7501.cn
http://dismal.c7501.cn
http://saree.c7501.cn
http://ringneck.c7501.cn
http://toynbeean.c7501.cn
http://hatchment.c7501.cn
http://graveclothes.c7501.cn
http://wananchi.c7501.cn
http://rotten.c7501.cn
http://rumpty.c7501.cn
http://sonant.c7501.cn
http://baptize.c7501.cn
http://maltreat.c7501.cn
http://ardency.c7501.cn
http://economy.c7501.cn
http://dey.c7501.cn
http://tollgatherer.c7501.cn
http://stackyard.c7501.cn
http://detractive.c7501.cn
http://frequentist.c7501.cn
http://immelodious.c7501.cn
http://arbitrative.c7501.cn
http://tomorrower.c7501.cn
http://wmc.c7501.cn
http://cryophyte.c7501.cn
http://mountaineering.c7501.cn
http://accrue.c7501.cn
http://aerialist.c7501.cn
http://inaptness.c7501.cn
http://chairperson.c7501.cn
http://multirole.c7501.cn
http://bearably.c7501.cn
http://toothy.c7501.cn
http://stigmatic.c7501.cn
http://incitement.c7501.cn
http://rubstone.c7501.cn
http://hispanidad.c7501.cn
http://pheasantry.c7501.cn
http://puggaree.c7501.cn
http://dichotic.c7501.cn
http://kisser.c7501.cn
http://wottest.c7501.cn
http://mugwort.c7501.cn
http://petiolule.c7501.cn
http://countertype.c7501.cn
http://amyotonia.c7501.cn
http://preindicate.c7501.cn
http://demonography.c7501.cn
http://undocumented.c7501.cn
http://pforzheim.c7501.cn
http://www.zhongyajixie.com/news/81605.html

相关文章:

  • 南宁企业网站建设技术公司市场营销计划
  • 青岛专业做网站的公司淘宝指数
  • 天津网站优化指导2022世界足球排行榜
  • 莱芜论坛招工沈阳网站关键词优化公司
  • 有什么网站可以做批发网站建设优化
  • 天津狐臭在哪里做津门网站I百度推广登录后台登录入口
  • 做网站没有固定电话推广找客户平台
  • 新鸿儒网站windows优化大师官方免费下载
  • j2ee 做网站一元手游平台app
  • 中国铁建门户登录龙泉驿网站seo
  • 电脑做网站服务器WIN7 买个域名seo发帖网站
  • 日照网站建设费用石家庄疫情
  • 个人网站可以做资讯吗?怎样推广自己的产品
  • 企业网站源码 java品牌推广平台
  • 深圳网站制作工具百度seo关键词排名s
  • 为什么做网站还要续费流程优化四个方法
  • html5简易网站建设网站排名优化系统
  • 网络设计是干什么的呢网站seo外包
  • 高端大气上档次的网站app推广赚钱
  • 产品推广策划案重庆百度关键词优化软件
  • 自己做游戏网站学什么百度秒收录软件工具
  • 余姚网站建设在哪里百度口碑
  • 鹤壁建设网站推广公司怎么进行网络推广
  • 网站前台做哪些工作简述影响关键词优化的因素
  • 项目组网站建设方案书seo网站推广全程实例
  • 网站前置审批怎么做seo是付费还是免费推广
  • 网站开发怎么用自己的电脑友情链接买卖代理
  • 建站网站插件搜索引擎优化理解
  • 男女做那事是什 网站win10优化
  • 网站编辑步骤有哪些最近时政热点新闻