首页>代码>java struts2实现文件批量上传下载功能(实现国际化配置)>/fileWithStruts2/src/com/shengke/action/FileDownloadForNameAction.java
package com.shengke.action;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.apache.commons.io.FileUtils;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 	类说明
 * @author  ShengKe
 * @version V1.0  创建时间:2015年1月28日 下午5:59:04
 */

public class FileDownloadForNameAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public String inputPath;
	public String filename;

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public String getInputPath() {
		return inputPath;
	}

	public void setInputPath(String inputPath) {
		this.inputPath = inputPath;
	}
	
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		
		return SUCCESS;
	}
	
	public InputStream getInputStream() throws IOException{
//		文件下载路径
//		String path=ServletActionContext.getServletContext().getRealPath("/images");
		String path="/home/shengke/workspace/fileWithStruts2/WebContent/images";
		System.out.println("path:"+path);
		String filepath=path+"/"+filename;
		File file=new File(filepath);
		
		return FileUtils.openInputStream(file);
		
	}
	
	public String getDownloadFileName() {
		String downloadFileName="";
		try {
			//这是设置下载时提示的文件名字,如果是中文,就转一下码
			downloadFileName=URLEncoder.encode("test.jpg","UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return downloadFileName;
	}
	

}
最近下载更多
wade123  LV31 2021年4月5日
死了还要爱  LV19 2020年9月6日
王晓敏  LV5 2020年5月18日
Chloez  LV7 2019年4月24日
best2018  LV46 2019年3月6日
大鹏小镇  LV14 2018年7月17日
root321  LV13 2018年1月1日
lizelin2236  LV7 2017年11月10日
wang888999  LV5 2017年8月9日
641031823  LV4 2017年5月2日
最近浏览更多
wangshule  LV14 1月8日
WBelong  LV7 2023年12月11日
uni-code_0123  LV1 2023年11月29日
qwerasdf123456  LV2 2022年4月24日
雷迪斯俺的乡亲们  LV11 2022年3月9日
zhangmingzuidaima  LV3 2021年12月16日
dongzhan  LV12 2021年12月15日
不停yayaya  LV4 2021年11月22日
EAST_Ace  LV4 2021年11月3日
zql666  LV9 2021年9月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友