⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileserviceimp.java

📁 一个自娱自乐的demo 开发环境 apache-tomcat-6.0.16 Mysql 5.1.11 Jdk 1.6 文件结构如下 --MyGame -----MyGam
💻 JAVA
字号:
package com.hb.base.services.common.imp;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.hb.base.services.common.IFileService;
import com.hb.base.util.Constant;
import com.hb.base.util.FacesContextUtil;
import com.hb.core.util.StringUtil;

/**
 * 2008/03/26
 * 
 * @author 何 貝
 * 
 * 名字后面多加了一个s主要是不想被Spring加入事务管理
 */
@Component("fileServices")
@Scope("prototype")
public class FileServiceImp implements IFileService {

	public boolean delEmpPhoto_Service(String employeeID) {
		// 相片
		File _file = new File(FacesContextUtil.getRealPath() + Constant.PHOTO_PATH + employeeID
				+ Constant.PHOTO_FILE_SUFFIX);
		if (_file.exists()) {
			_file.delete();
			return true;
		}

		return false;
	}

	public String getPhotoFilePath_Service(String employeeID) {
		// 相片
		File _file = new File(FacesContextUtil.getRealPath() + Constant.PHOTO_PATH + employeeID
				+ Constant.PHOTO_FILE_SUFFIX);
		if (_file.exists()) {
			return Constant.PHOTO_PATH + employeeID + Constant.PHOTO_FILE_SUFFIX;
		} else {
			return null;
		}
	}

	public boolean savePhotoFile_Service(String employeeID, InputStream fileData) throws IOException {
		String filePath = FacesContextUtil.getRealPath() + Constant.PHOTO_PATH + employeeID
				+ Constant.PHOTO_FILE_SUFFIX;

		return saveFile_Service(filePath, fileData);
	}

	public boolean saveFile_Service(String filePath, InputStream fileData) throws IOException {
		if (!StringUtil.isEmpty(filePath) && fileData != null) {
			final int bufferSize = 1000;
			File file = new File(filePath);

			FileOutputStream fout = new FileOutputStream(file);
			byte[] buffer = new byte[bufferSize];
			int readCount = 0;
			while ((readCount = fileData.read(buffer)) != -1) {
				if (readCount < bufferSize) {
					fout.write(buffer, 0, readCount);
				} else {
					fout.write(buffer);
				}
			}
			fout.close();
			fileData.close();

			return true;
		} else {
			return false;
		}

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -