⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clsupload.java

📁 一个完整的
💻 JAVA
字号:
package com.gforce.currency.clsupload;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.io.*;
import java.util.*;
import com.gforce.currency.*;

/**
 * <p>Title: 吉力科技办公自动化系统</p>
 * <p>Description: 吉力科技办公自动化系统</p>
 * <p>Copyright: 版权所有 2003 (c) 西安吉力科技发展有限公司  Copyright (c) 2003 GForce Sceince & Technology</p>
 * <p>Company: 西安吉力科技发展有限公司 (GForce Sceince & Technology)</p>
 * @author 马登军
 * @version 1.0
 */

public class ClsUpload
{
    private ClsMultipartProcess cmp;
    private ServletContext scApplication;


    public ClsUpload(PageContext JspPageContext)
    {
        scApplication = JspPageContext.getServletContext();
        cmp = new ClsMultipartProcess((HttpServletRequest)JspPageContext.getRequest());
    }

    public String getValue(String controlName)
    {
        return cmp.getValue(controlName);
    }

    public String fileAdd(String controlName, String strtempPath)
    {
      String strFileName = uploadFile(controlName,strtempPath);
      if(strFileName.indexOf(",")>0)
      {
        return strFileName.substring(0,strFileName.indexOf(","));
      }
      else
      {
        return strFileName;
      }
    }

    public boolean fileDelete(String fileName)
    {
        String deleteName = scApplication.getRealPath(fileName);
        boolean flag = false;

        try
        {
            deleteName = new String(deleteName.getBytes("ISO8859-1"));
        }
        catch (UnsupportedEncodingException ex)
        {
            ex.printStackTrace();
        }

        File file = new File(deleteName.substring(0,deleteName.lastIndexOf("/")-1));
        flag = file.delete();

        return flag;
    }

    public void finishUpload(String fileList, String srcPath, String destPath)
    {
        srcPath = scApplication.getRealPath(srcPath) +"/";
        destPath = scApplication.getRealPath(destPath) +"/";
        StringTokenizer strToken = new StringTokenizer(fileList, ";");
        String[] file = new String[strToken.countTokens()];

        for (int i = 0; strToken.hasMoreTokens(); i++)
        {
            file[i] = strToken.nextToken();
            String fileName = file[i].substring(0, file[i].lastIndexOf("."));
            String tempDocPath = srcPath + "/" + file[i];
            String destDocPath = destPath + "/" + fileName;

            try
            {
                tempDocPath = new String(tempDocPath.getBytes("ISO8859-1"));
                destDocPath = new String(destDocPath.getBytes("ISO8859-1"));
            }
            catch (UnsupportedEncodingException ex)
            {
                ex.printStackTrace();
            }

            File srcFile = new File(tempDocPath);
            File destFile = new File(destDocPath);

            srcFile.renameTo(destFile);
        }
    }


    public String uploadFile(String controlName, String strtempPath)
    {
        String name = "";
        String tempPath = scApplication.getRealPath(strtempPath) +"/";
        String now = StringNew.GetDateString(new Date(),"yyyy/MM/dd/HHmmssSSS");
        String fileName = cmp.getFileName(controlName);
        String strDestFileName = (new Random()).nextInt(999999) + fileName.substring(fileName.lastIndexOf("."));
        String fileContent = cmp.getFileContent(controlName);

        File file = new File(tempPath + now + "/" + strDestFileName);
        try
        {
            if (!file.exists())
            {
                file.mkdirs();
            }

            FileOutputStream fileOut = new FileOutputStream(tempPath + now + "/" + strDestFileName + "/" + strDestFileName);
            fileOut.write(fileContent.getBytes("ISO8859-1"), 0, fileContent.length());
            name = strtempPath + "/" + now + "/" + strDestFileName + "/" + strDestFileName + "," + fileName;
            fileOut.close();
        }
        catch (FileNotFoundException ex)
        {
            ex.printStackTrace();
        }
        catch (UnsupportedEncodingException ex)
        {
            ex.printStackTrace();
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            return name;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -