| | |
| | |
|
| | | 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;
|
| | | // 提交过来的file的名字
|
| | |
| | | }
|
| | | 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;
|
| | |
| | | public void setBattname(String battname) {
|
| | | this.battname = battname;
|
| | | }
|
| | | |
| | | |
| | | |
| | | public static void main(String[] args) {
|
| | | String filePath = "D:/test/a/a.txt";
|
| | | ActionUtil.createFileRootIFNotExist(filePath);
|
| | | }
|
| | | }
|