src/com/action/UploadAction.java

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package com.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.util.VeDate;

public class UploadAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	// 封装上传文件域的属性
	private File image;
	// 封装上传文件类型的属性
	private String imageContentType;
	// 封装上传文件名的属性
	private String imageFileName;
	// 接受依赖注入的属性
	private String savePath;

	public String execute() {
		FileOutputStream fos = null;
		FileInputStream fis = null;
		int i = getImageFileName().indexOf(".");
		String name = String.valueOf(VeDate.getStringDatex());
		String type = getImageFileName().substring(i + 1);
		this.setImageFileName(name + "." + type);
		this.setSavePath("upfiles");
		try {
			// 建立文件输出流
			fos = new FileOutputStream(getSavePath() + "\\"
					+ getImageFileName());
			// 建立文件上传流
			fis = new FileInputStream(getImage());
			byte[] buffer = new byte[1024];
			int len = 0;
			while ((len = fis.read(buffer)) > 0) {
				fos.write(buffer, 0, len);
			}
		} catch (Exception e) {
			System.out.println("文件上传失败");
			e.printStackTrace();
		} finally {
			close(fos, fis);
		}
		return "success";
	}

	/**
	 * 返回上传文件的保存位置
	 * 
	 * @return
	 */
	public String getSavePath() throws Exception {
		return ServletActionContext.getServletContext().getRealPath(savePath);
	}

后面还有 47 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。