From 50e8d04827ba49d191d7cf6f4632a9065246cb83 Mon Sep 17 00:00:00 2001
From: LiJun <LiJun@192.168.10.30>
Date: 星期五, 16 十一月 2018 16:43:06 +0800
Subject: [PATCH] 视频上传后台添加
---
gx_tieta/src/com/fgkj/actions/MyFileAction.java | 66 +++++++++++++++++++++++++++++++++
gx_tieta/src/com/fgkj/actions/ActionUtil.java | 38 ++++++++++++++++++
2 files changed, 103 insertions(+), 1 deletions(-)
diff --git a/gx_tieta/src/com/fgkj/actions/ActionUtil.java b/gx_tieta/src/com/fgkj/actions/ActionUtil.java
index 86367a7..edb0b51 100644
--- a/gx_tieta/src/com/fgkj/actions/ActionUtil.java
+++ b/gx_tieta/src/com/fgkj/actions/ActionUtil.java
@@ -1,5 +1,6 @@
package com.fgkj.actions;
+import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -491,8 +492,43 @@
this.key = key;
}
+ /**
+ * 鍒涘缓鎸囧畾鐨勬枃浠舵枃浠讹紝鑻ヤ笉瀛樺湪鍒欏厛鍒涘缓鎸囧畾鐨勬枃浠跺す鍐嶅垱寤烘寚瀹氱殑鏂囦欢
+ * @param filePath
+ */
+ public static void createFileRootIFNotExist(String filePath){
+ File f = new File(filePath);
+ if(!f.exists()){
+ if(!f.getParentFile().exists()){
+ f.getParentFile().mkdirs();
+ }
+ try {
+ f.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 鍒涘缓鎸囧畾鐨勬枃浠舵枃浠讹紝鑻ヤ笉瀛樺湪鍒欏厛鍒涘缓鎸囧畾鐨勬枃浠跺す鍐嶅垱寤烘寚瀹氱殑鏂囦欢
+ * @param filePath
+ */
+ public static void createFilefolderIFNotExist(String filePath){
+ File f = new File(filePath);
+ if(!f.exists()){
+ if(!f.getParentFile().exists()){
+ f.getParentFile().mkdirs();
+ }
+ }
+ }
+
+
public static void main(String[] args) {
String str = "绂忓厜鐢靛瓙";
- System.out.println(EncryptionMD5(EncryptionMD5(str)));
+ //System.out.println(EncryptionMD5(EncryptionMD5(str)));
+
+
+ createFilefolderIFNotExist("d:/aaaa/aaaa/aaaa/aaaa/ddd.txt");
}
}
diff --git a/gx_tieta/src/com/fgkj/actions/MyFileAction.java b/gx_tieta/src/com/fgkj/actions/MyFileAction.java
index faf8a3d..8bc9101 100644
--- a/gx_tieta/src/com/fgkj/actions/MyFileAction.java
+++ b/gx_tieta/src/com/fgkj/actions/MyFileAction.java
@@ -2,16 +2,20 @@
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
+import com.fgkj.dto.BattInf;
import com.fgkj.dto.ServiceModel;
import com.google.gson.Gson;
public class MyFileAction extends ActionUtil{
+
private String result;
+ private String json;
private String battname;
private File[] file;
// 鎻愪氦杩囨潵鐨刦ile鐨勫悕瀛�
@@ -167,6 +171,61 @@
}
return flag;
}
+
+ //涓婁紶鏈烘埧瑙嗛鎺ュ彛
+ public String uploadStationFile(){
+ BattInf binf = getGson().fromJson(json, BattInf.class);
+ String fileRoot = "staionsrc";
+ ServiceModel model = new ServiceModel();
+ boolean isSuccess = false;
+ String loadpath = ActionUtil.getSession().getServletContext().getRealPath("/");
+ String str = new File(loadpath).getParentFile().getAbsolutePath(); //鑾峰彇鏈嶅姟鍣ㄦ墍鍦ㄧ殑缁濆璺緞
+ String root = str+"/"+fileRoot+"/"+binf.getStationId()+"/vide/"; // 涓婁紶璺緞
+ for(int i=0;i<file.length;i++){
+ String filePath = root+fileFileName[i];
+ createFilefolderIFNotExist(filePath);
+ copyFile(file[i], filePath);
+ }
+ result = tojson(model);
+ return SUCCESS;
+ }
+
+
+ public static void copyFile(File oldFile, String newPath){
+ File file = new File(newPath);
+ FileInputStream in = null;
+ FileOutputStream out = null;
+ try {
+ in = new FileInputStream(oldFile);
+ out = new FileOutputStream(file);;
+
+ byte[] buffer=new byte[2097152];
+ int readByte = 0;
+ while((readByte = in.read(buffer)) != -1){
+ out.write(buffer, 0, readByte);
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if(in != null){
+ try {
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if(out != null){
+ try {
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
public void setFilestr(String filestr) {
this.filestr = filestr;
@@ -196,4 +255,11 @@
public void setBattname(String battname) {
this.battname = battname;
}
+
+
+
+ public static void main(String[] args) {
+ String filePath = "D:/test/a/a.txt";
+ ActionUtil.createFileRootIFNotExist(filePath);
+ }
}
--
Gitblit v1.9.1