package action;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
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 util.ClearTemp;
import util.FlashPaper;
import com.opensymphony.xwork2.ActionSupport;
import constant.Constant;
/**
*
* <p>Title: FileUploadAction.java</p>
*
* <p>Description: </p>
*
* <p>Date: Jul 8, 2011</p>
*
* <p>Time: 2:22:05 PM</p>
*
* <p>Copyright: 2011</p>
*
* <p>Company: HuajuN</p>
*
* @author 刘玉华
* @version 1.0
*
* <p>============================================</p>
* <p>Modification History
* <p>Mender: </p>
* <p>Date: </p>
* <p>Reason: </p>
* <p>============================================</p>
*/
public class FileUploadAction extends ActionSupport {
private static final long serialVersionUID = 572146812454l;
private static final int BUFFER_SIZE = 1024;
private File file;
private String fileContentType;
private String fileFileName;
private boolean flag;
private String imageFileName;
private Constant con=new Constant();
/**
* 获得上传文件后缀
* @param fileContentType
*/
public void setFileContentType(String fileContentType) {
if (fileContentType.contains("msword")) {
this.fileContentType = ".doc";
} else if (fileContentType.contains("excel")) {
this.fileContentType = ".xls";
} else if (fileContentType.contains("pdf")) {
this.fileContentType = ".pdf";
} else if (fileContentType.contains("powerpoint")) {
this.fileContentType = ".ppt";
} else {
this.fileContentType = ".doc";
}
}
/**
* copy文件src至dir
* @param src
* @param dir
*/
private static void copyFile(File src, File dir) {
try {
InputStream input = null;
OutputStream output = null;
try {
input = new BufferedInputStream(new FileInputStream(src), BUFFER_SIZE);
output = new BufferedOutputStream(new FileOutputStream(dir),BUFFER_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
while (input.read(buffer) > 0) {
output.write(buffer);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != input) {
input.close();
}
if (null != output) {
output.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 上传 转换
* @return
*/
public String upload() {
imageFileName = createID();
File dirFile = new File(con.getDocfolderpath() + imageFileName
+ this.getFileContentType());
copyFile(file, dirFile);
int fileSize = 0;
try {
fileSize = new FileInputStream(file).available() / 1024;
} catch (Exception e) {
e.printStackTrace();
}
//上传文件名和swf文件名一致
flag = FlashPaper.converter(imageFileName, imageFileName
+ this.getFileContentType(), fileSize);
ClearTemp.clearTemp();//手动清除上传缓存文件
return "suc";
}
/**
* 随机生成32位字符串
*
* @return str
*/
private String createID() {
String uu = UUID.randomUUID().toString();
String[] uus = uu.split("-");
String str = "";
for (int i = 0; i < uus.length; i++) {
str += uus[i];
}
return str;
}
//setter and getter
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getImageFileName() {
return imageFileName;
}
public void setImageFileName(String imageFileName) {
this.imageFileName = imageFileName;
}
public String getFileContentType() {
return fileContentType;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
利用FlashPaper实现类似百度文库功能Demo
共38个文件
jar:7个
java:6个
class:6个
4星 · 超过85%的资源 需积分: 9 201 下载量 49 浏览量
2013-03-25
14:39:02
上传
评论 4
收藏 3.18MB ZIP 举报
温馨提示
利用FlashPaper实现类似百度文库功能 Demo 这是个简单的Demo 各位可以参考下 更复杂的功能需要各位自己去演绎了 我
资源推荐
资源详情
资源评论
收起资源包目录
SwfDoc.zip (38个子文件)
SwfDoc
.project 1KB
.mymetadata 292B
src
action
FileUploadAction.java 4KB
ViewAction.java 1014B
struts.xml 818B
constant
Constant.java 2KB
util
FlashPaper.java 2KB
Confuse.java 1KB
ClearTemp.java 1KB
struts.properties 129B
path.properties 315B
WebRoot
WEB-INF
classes
action
ViewAction.class 791B
FileUploadAction.class 4KB
struts.xml 818B
constant
Constant.class 2KB
util
Confuse.class 1KB
FlashPaper.class 1KB
ClearTemp.class 1KB
struts.properties 129B
path.properties 315B
lib
xwork-core-2.1.6.jar 1.49MB
freemarker-2.3.15.jar 859KB
struts2-core-2.1.8.1.jar 738KB
commons-logging.jar 59KB
commons-io-1.3.2.jar 86KB
commons-fileupload-1.2.1.jar 56KB
ognl-2.7.3.jar 234KB
web.xml 1KB
upload.jsp 582B
js
swfobject.js 14KB
document
META-INF
MANIFEST.MF 39B
succeed.jsp 425B
swffiles
view.jsp 878B
swf
non.swf 1KB
expressInstall.swf 727B
.myeclipse
.settings
org.eclipse.jdt.core.prefs 330B
com.genuitec.eclipse.j2eedt.core.prefs 1KB
.classpath 921B
共 38 条
- 1
liuyuhua0066
- 粉丝: 225
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页