上传视频至本地文件夹(文件也可以上传)java代码
来源:互联网 发布:web前端实战项目源码 编辑:程序博客网 时间:2024/06/14 08:22
视频上传 Controller:
private final static String UPLOADDIR = "/new_resource/video"; //上传文件存放路径
private List<File> file; //上传文件集合
private List<String> fileFileName; //上传文件名集合
private List<String> fileContentType; //上传文件内容类型集合
private void uploadFile(int i) throws FileNotFoundException, IOException {
try {
InputStream in = new FileInputStream(file.get(i));
String dir = ServletActionContext.getRequest().getRealPath(UPLOADDIR);//文件路径
File fileLocation = new File(dir);
//此处也可以在应用根目录手动建立目标上传目录
if(!fileLocation.exists()){
boolean isCreated = fileLocation.mkdir();
if(!isCreated) {
return;
}
}
String fileName=this.getFileFileName().get(i);
File uploadFile = new File(dir, fileName);
OutputStream out = new FileOutputStream(uploadFile);
byte[] buffer = new byte[1024 * 1024];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
in.close();
out.close();
} catch (FileNotFoundException ex) {
System.out.println("上传失败!");
ex.printStackTrace();
} catch (IOException ex) {
System.out.println("上传失败!");
ex.printStackTrace();
}
}
//添加视频信息
public String saveVideo() throws Exception {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(currentTime);
ParsePosition pos = new ParsePosition(0);
Date tjsj = formatter.parse(dateString, pos);
String videoname=fileFileName.get(0);//获取上传文件的名称
TbVideo video = new TbVideo();
video.setVname(vname);
video.setVurl(videoname);
video.setVperson(vperson);
video.setVsoft(vsoft);
video.setPubtime(new Date());
video.setComments(msgEditor);
this.webService.saveVideo(video);
System.out.println(this.getFileFileName());
for (int i = 0; i < file.size(); i++) {
uploadFile(i); //循环上传每个文件
}
return SUCCESS;
}
视频上传 jsp
<tr>
<th width="20%">上传附件:</th>
<td width="42%" >
<label>
<input name="file" id="upFile" type="file"/>
</label><font color="red" style="white-space:nowrap;">*上传视频</font>
</td>
</tr>
- 上传视频至本地文件夹(文件也可以上传)java代码
- JAVA 影像上传至本地/服务器的某一文件夹
- Java servlet上传文件(照片视频)
- java 上传文件到本地
- JAVA代码上传文件
- JAVA文件上传代码
- 上传代码至github-------------本地上传
- 上传本地视频
- 上传本地视频
- git上传java项目代码(初次上传,以后可以用elipse插件上传)
- C# FTP上传文件及文件夹至服务器代码
- linux上传文件夹也疯狂
- C# winform 文件浏览选择上传至本地服务器HttpWebClient+调用本地文件夹
- android上传图片、视频、大文件代码
- PhoneGap 文件上传(Java 后台代码)
- FMS学习(五):上传本地视频
- 上传本地代码到github上面,怎么忽略node_modules文件夹
- 纯java代码文件上传
- Java组合实体模式
- AABB
- opencv-视频分析
- pandas.read_csv参数解释
- Java异常---Illegal access: this web application instance has been stopped already
- 上传视频至本地文件夹(文件也可以上传)java代码
- U盘重装系统window10换window7
- 几种UDP网络库的整理Raknet,UDT,ENet,lidgren-network-gen3
- 线性因素和非线性因素各指什么
- 浅谈sql中的in与not in,exists与not exists的区别
- 三大架构的比较
- 怎么使用bootstrap后台admin模板-bootstrap视频教程4
- 《Linux内核设计与实现》读书笔记(二)- 内核开发的准备
- URL地址的拼接