?? fileupexecute.java
字號:
package com.david.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.upload.FormFile;
public class FileUpExecute implements IFileUpExecute {
private FormFile formFile;
private IFileUtil fileUtil;
public byte[] getFileData() {
// TODO Auto-generated method stub
try {
return this.formFile.getFileData();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public String getFileName() {
// TODO Auto-generated method stub
//return this.formFile.getFileName();
return UUID.randomUUID().toString()+"."+this.getFileSuffix();
}
public String getFileSuffix() {
// TODO Auto-generated method stub
return this.fileUtil.getFileSuffix(this.formFile.getFileName());
}
public void init(FormFile formFile) {
// TODO Auto-generated method stub
this.formFile=formFile;
}
public String saveAs(HttpServletRequest request, String path) {
// TODO Auto-generated method stub
try {
String absPath=new File(fileUtil.changePathToAbsol(request, path),this.getFileName()).getAbsolutePath();
FileOutputStream out=new FileOutputStream(absPath);
try {
out.write(formFile.getFileData());
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//返回絕對路徑
//return fileUtil.changePathToRelative(request, absPath);
return absPath;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public void setFileUtil(IFileUtil fileUtil) {
// TODO Auto-generated method stub
this.fileUtil=fileUtil;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -