linus上运行jar包文件增删查
package com.osplat.util;
import com.alibaba.fastjson.JSON;
import com.osplat.bean.Resultmodel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
/**
* @Company:wftdlx
* @Author: wjf
* @Description:
* @Date: Created in 15:48 2019/2/19
*/
/**yml文件中
web:
#uploadPath: E:\\files\\
uploadPath: /home/numa/image/
*/
@Component
public class LinusFile {
//public static String imageUrl="/home/numa/image/";//linus路径
//public static String imageUrl="E:\\files\\";//window路径
public static String imageUrl;
@Value("${web.uploadPath}")
public void setImageUrl(String uploadPath) {
imageUrl = uploadPath;
}
//直接上传
public static Resultmodel upFile(MultipartFile file) {
Log.info("开始文件上传");
if (file.isEmpty()) {
String msg = "上传文件不能为空";
Log.info(msg);
return new Resultmodel(0, "上传失败");
}
String fileName = file.getOriginalFilename();
Log.info("文件名=" + fileName);
//加个时间戳,尽量避免文件名称重复
long l = System.currentTimeMillis();
fileName = l + "_" + fileName;
Log.info("保存的文件名为=" + fileName);
// 获得的系统的根目录
File fileParent = new File(File.separator);
// 获得/usr/CBeann目录
File PathBefore = new File(fileParent, imageUrl + fileName);
//创建文件路径
File dest = PathBefore;
//上传文件
try {
file.transferTo(dest); //保存文件;
} catch (Exception e) {
Log.error("异常:" + "上传失败异常" + e.getMessage());
return new Resultmodel(-1, "上传失败异常");
}
return new Resultmodel(0, "上传成功", fileName);
}
//查询图片
public static Resultmodel show(HttpServletResponse response, String data) {
//String page,String pageSize,String finishKey
//开始
Log.info("======开始:图片查看");
Log.info("入参data:" + data);
//数据转换
Map maps = (Map) JSON.parse(data);//import com.alibaba.fastjson.JSON;
String imgUrl = maps.get("imgUrl").toString();
//String photoName = "0d34f75a26334f6f836512b52d09053ce37eb12612f628c1c3d37fd8fffdff28.jpg";
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
response.setContentType("image/jpeg");
// 获得的系统的根目录
File fileParent = new File(File.separator);
// 获得/usr/CBeann目录
File file = new File(fileParent, imageUrl + imgUrl);
try {
BufferedImage bi = ImageIO.read(new FileInputStream(file));
ServletOutputStream out = response.getOutputStream();
ImageIO.write(bi, "jpg", out);
try {
out.flush();
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
Log.error("查看图片异常" + e.getMessage());
return new Resultmodel(Resultmodel.ERROR, "查看图片异常");
}
return null;
}
//删除图片
public static Resultmodel delete(HttpServletResponse response, String data) {
//开始
Log.info("======开始:图片删除");
Log.info("入参data:" + data);
//数据转换
Map maps = (Map) JSON.parse(data);//import com.alibaba.fastjson.JSON;
String imgUrl = maps.get("imgUrl").toString();
Log.info("转换后数imgUrl:" + imgUrl);
// 获得的系统的根目录
File fileParent = new File(File.separator);
// 获得/usr/CBeann目录
File file = new File(fileParent, imageUrl + imgUrl);
Log.info("转换后数file:" + file.toString());
//删除文件
boolean delete = false;
try {
delete = file.delete();//保存文件;
Log.info("转换后数delete:" + delete);
if (delete) {
return new Resultmodel(0, "图片删除成功");
}
return new Resultmodel(-1, "图片删除失败");
} catch (Exception e) {
Log.error("异常:" + "上传失败异常" + e.getMessage());
return new Resultmodel(-1, "上传失败异常");
}
}
}
配置文件yml
# 取消模板文件缓存
thymeleaf:
cache: false
enabled: false
servlet:
multipart:
max-file-size: 128KB
max-request-size: 128KB
enabled: false
配置路径yml:
web: #uploadPath: E:\\files\\ uploadPath: /home/numa/image/
@Configuration注解文件下添加
//文件上传
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
// 单个文件最大
factory.setMaxFileSize("201400KB"); // KB, MB
// 设置上传数据总大小
factory.setMaxRequestSize("2014000KB");
return factory.createMultipartConfig();
}
linus上运行jar包文件增删查的更多相关文章
- 在服务器上运行Jar包
在服务器上运行Jar包 并且该Jar包依赖其他的Jar文件的时候,采用如下格式 java -Djava.ext.dirs=你依赖的Jar文件路径 -jar 你要运行的Jar文件 包名+类名 例如: j ...
- 在Linux服务器上运行jar包,并且使jar包一直处于后台执行
1.我jar包在linux的目录为/a/bbb.jar 正常情况下,使用在/a目录下使用 java -jar bbb.jar 可以直接运行该jar包的项目,运行成功之后使用crtl+ ...
- 如何打包/运行jar包,及生成exe文件
关于如何打包/运行jar包,以及生成exe文件.之前各种查询.博客,终于搞明白究竟是咋回事.记得还做过笔记的.今天要打包生成exe用的时候,居然忘了咋怎来着.去查看之前的笔记,死活没找到(好像被删掉了 ...
- Linus运行jar包的操作
cd / 返回最顶层文件夹cd home/numa 进入home下的numa文件夹ll 查看当前文加夹下的所有文件ps -ef | grep java ...
- 在linux云服务器上运行Jar文件
在linux服务器上运行Jar文件时通常的方法是: $ java -jar test.jar 这种方式特点是ssh窗口关闭时,程序中止运行.或者是运行时没法切出去执行其他任务,有没有办法让Jar在后台 ...
- Java Web文件上传原理分析(不借助开源fileupload上传jar包)
Java Web文件上传原理分析(不借助开源fileupload上传jar包) 博客分类: Java Web 最近在面试IBM时,面试官突然问到:如果让你自己实现一个文件上传,你的代码要如何写,不 ...
- hadoop_MapReduce_idea上打jar包,在虚拟机上运行
打包前的介绍和准备工作 指定主类可以在运行jar包的时候不用输入要运行哪一个类,直接就可以运行了 指定主类 编辑jar 的信息 修改jar包的名称 build Complete!!! MapReduc ...
- 不显示cmd窗口运行jar包
今天,打开导出的jar包,发现并不能运行,查看jar包中的META-INF文件夹下的MANIFEST.MF文件,发现MANIFEST.MF中并没有Main-Class,于是,就手动添加相应的信息,本项 ...
- IDEA2017版本打可运行jar包并运行
一.打JAR包 JAR:From modules with dependencies 将依赖一起打包 一般依赖放在与xx.jar同级的libs文件夹中 敲黑板,下图第一个框是输出jar包的位置,第二 ...
随机推荐
- [Unity插件]Lua行为树(四):条件节点和行为节点
条件节点和行为节点,这两种节点本身的设计比较简单,项目中编写行为树节点一般就是扩展这两种节点,而Decorator和Composite节点只需要使用内置的就足够了. 它们的继承关系如下: Condit ...
- Java课程作业之动手动脑(五)
1.请阅读并运行AboutException.java示例. import javax.swing.*; class AboutException { public static void main( ...
- 关于php中的exec命令
这个命令 一般是被禁用的 一些特殊需求的时刻 可以启用 比如 调用系统上的一些数据或者命令 $command ='/www/wwwroot/t.6328.net/Public/cfile/test' ...
- 《算法》第四章部分程序 part 1
▶ 书中第四章部分程序,加上自己补充的代码,包含无向 / 有向图类 ● 无向图类 package package01; import java.util.NoSuchElementException; ...
- python学习笔记_week5_模块
模块 一.定义: 模块:用来从逻辑上组织python代码(变量,函数,类,逻辑:实现一个功能), 本质就是.py结尾的python文件(文件名:test.py,对应模块名:test) 包:用来从逻辑上 ...
- iOS基础知识之归档和解档
归档和解档:即将数据写入文件和从文件中读取数据. 此处以plist文件为例说明, 一.plist文件使用时的注意事项: 1.plist文件中仅支持写入Array,Dictionary,Boolean, ...
- C# 设计模式-策略者模式(Strategy)
策略模式的用意是针对一组算法,将每一个算法封装到具有共同接口的独立的类中,从而使得它们可以相互替换.策略模式使得算法可以在不影响到客户端的情况下发生变化. 策略模式是对算法的包装,是把使用算法的责任和 ...
- 设置SVN服务器
1 下载svn服务器,参考地址 http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html 下载地址: http://subv ...
- linux驱动开发( 五) 字符设备驱动框架的填充file_operations结构体中的操作函数(read write llseek unlocked_ioctl)
例子就直接使用宋宝华的书上例子. /* * a simple char device driver: globalmem without mutex * * Copyright (C) 2014 Ba ...
- Centos7 Minimal 安装后 初始化配置
安装完成后初始化配置 1:更新yum yum upgrade 2: 安装基础命令 #yum -y install vim* lrzsz gcc-c++ pcre pcre-devel zlib zli ...