📄 uploadbiz.java
字号:
package com.yhcms.manage.upload.biz;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.log4j.Logger;
import org.apache.struts.upload.FormFile;
import com.yhcms.db.DBConnException;
import com.yhcms.manage.upload.action.UpLoadAction;
import com.yhcms.manage.upload.bean.UpFile;
import com.yhcms.manage.upload.dao.UpFileDaoIm;
import com.yhcms.manage.upload.itface.UpFileDao;
/**
* <p>Title:系统上传附件BIZ</p>
* <li>系统上传附件</li>
* <br><b>CopyRight: yyhweb[由由华网]</b>
* @author stephen
* @version YH-2.0
*/
public class UpLoadBiz{
static Logger yhlog = Logger.getLogger(UpLoadAction.class.getName());
public static boolean writeFile(FormFile curFile, String filePath) {
boolean noExcp = true;
InputStream input = null;
OutputStream output = null;
try {
input = curFile.getInputStream();
output = new FileOutputStream(filePath);
int size = 0;
byte temp[] = new byte[8192];
while ((size = input.read(temp, 0, 8192)) != -1)
output.write(temp, 0, size);
temp = (byte[]) null;
}
catch (Exception e) {
noExcp = false;
e.printStackTrace();
}
finally {
try {
if (input != null) {
input.close();
input = null;
}
if (output != null) {
output.close();
output = null;
}
if (curFile != null) {
curFile.destroy();
curFile = null;
}
}
catch (Exception e) {
noExcp = false;
e.printStackTrace();
}
}
return noExcp;
}
public static boolean delFile(String filePath) {
try {
File delfile = new File(filePath);
boolean temp = false;
if (delfile.exists())
temp = delfile.delete();
delfile = null;
return temp;
}
catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static void uploadDao(UpFile curFile){
boolean flag = false;
UpFileDao fileDao = UpFileDaoIm.getInstance();
try {
flag = fileDao.uploadFile(curFile);
}
catch (DBConnException e) {
yhlog.warn("Add a upload file information,throw an Exception!File name is:"+curFile.getFilename());
}
if(!flag){
yhlog.warn("Add a upload file information unsuccessfully.File name is:"+curFile.getFilename());
}
return ;
}
public static void deleteDao(int fileId){
boolean flag = false;
UpFileDao fileDao = UpFileDaoIm.getInstance();
try {
flag = fileDao.delFile(fileId);
}
catch (DBConnException e) {
yhlog.warn("Delete a upload file information,throw an Exception!File id is:"+fileId);
}
if(!flag){
yhlog.warn("Delete a upload file information unsuccessfully.File id is:"+fileId);
}
return ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -