• struts 文件上传示例


    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.UUID;
    
    import org.apache.commons.io.FilenameUtils;
    import org.apache.struts2.ServletActionContext;
    
    import com.opensymphony.xwork2.ActionSupport;
    
    public class uploadAction extends ActionSupport {
        private File uploadpic;
        private String uploadpicContentType;
        private String uploadpicFileName;
    
        /**
         * @return
         */
        public String execute() throws Exception  {
            // TODO Auto-generated method stub
            InputStream is = new FileInputStream(uploadpic);
            String photoPath = ServletActionContext.getServletContext()
                    .getRealPath("/images");
            File filePhotoPath = new File(photoPath);
            if (!filePhotoPath.isDirectory()) {
                filePhotoPath.mkdir();
            }
    
            String extension = FilenameUtils.getExtension(this.getUploadpicFileName());
            String filename = UUID.randomUUID().toString() + "." + extension;
    
            File tofile = new File(photoPath, filename);
    
            OutputStream os = new FileOutputStream(tofile);
            byte[] buffer = new byte[1024];
            int length = 0;
            while ((length = is.read(buffer)) > 0) {
                os.write(buffer, 0, length);
            }
            is.close();
            os.close();
    
            return SUCCESS;
        }
    
        public File getUploadpic() {
            return uploadpic;
        }
    
        public void setUploadpic(File uploadpic) {
            this.uploadpic = uploadpic;
        }
    
        public String getUploadpicContentType() {
            return uploadpicContentType;
        }
    
        public void setUploadpicContentType(String uploadpicContentType) {
            this.uploadpicContentType = uploadpicContentType;
        }
    
        public String getUploadpicFileName() {
            return uploadpicFileName;
        }
    
        public void setUploadpicFileName(String uploadpicFileName) {
            this.uploadpicFileName = uploadpicFileName;
        }
    
    }
  • 相关阅读:
    Mach-O 加载命令(Load commands)
    Mach-O文件介绍之loadcommand
    趣探 Mach-O:加载过程
    Forking and Executing the Process
    XNU加载Mach-O和dyld
    OSX内核加载mach-o流程
    App Launch Sequence on iOS
    操作系统 = 内核 + 服务
    OS X kernel architecture
    OSX架构概述
  • 原文地址:https://www.cnblogs.com/mrcharles/p/11879887.html
Copyright © 2020-2023  润新知