📄 gsdspdownload.java
字号:
package jp.co.sjts.gsession.tools;
import java.io.File;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import javax.servlet.http.HttpServletResponse;
/**
* <p>僶僀僫儕僼傽僀儖僟僂儞儘乕僪僋儔僗
* <p>僽儔僂僓偱昞帵弌棃傞暔偼丄昞帵偡傞
*
* @author Satoru K <koni@sjts.co.jp>
*/
public class GSDspDownLoad{
/** 僼傽僀儖 */
private File file;
/** 僼傽僀儖柤 */
private String dstFilename;
/** ContentType */
private String contentType=null;
/**
* <p>僐儞僗僩儔僋僞
*
* @param path 僷僗
* @param dstFilename 僼傽僀儖柤
*/
public GSDspDownLoad(String path,String dstFilename){
file = new File(path);
this.dstFilename = dstFilename;
}
/**
* <p>僐儞僗僩儔僋僞
*
* @param path
* @param dstFilename
* @param contentType
*/
public GSDspDownLoad(String path,String dstFilename,String contentType){
file = new File(path);
this.dstFilename = dstFilename;
this.contentType = contentType;
}
/**
* <p>ContentType傪僙僢僩偟傑偡丅
*
* @param contentType ContentType
*/
public void setContentType(String contentType){
this.contentType = contentType;
}
/**
* <p>弌椡
*/
public void write(HttpServletResponse res) throws GSException{
try{
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream out = new BufferedOutputStream(res.getOutputStream());
if(contentType!=null)
res.setContentType(contentType);
int i;
while((i=in.read()) >= 0){
out.write(i);
}
out.flush();
in.close();
out.close();
}catch(FileNotFoundException e){
}catch(IOException e){
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -