首页>代码>axis2 webservice实现文件上传删除功能>/FileUploadInfo/src/com/fileup/upservice/FileUploadService.java
package com.fileup.upservice;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 文件上传webservice
 * 
 * @author root
 * 
 */
public class FileUploadService {
	/**
	 * 设置上传文件所需参数
	 * 
	 * @param declare
	 * @param endName
	 * @param outputStream
	 * @return
	 */
	public String uploadFile(String declare, String endName, byte[] outputStream) {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		String dateStr = sdf.format(date);
		FileOutputStream out = null;
		String filePath = this.getClass().getClassLoader().getResource("/")
				.getPath();
		//可以通过输出路径查看文件的上传路径
		System.out.println("################" + filePath + "#################");
		filePath = filePath.substring(1, filePath.length());
		String realUrl = filePath + "upload";
		if (!new File(realUrl).isDirectory())
			new File(realUrl).mkdirs();
		try {
			String fileName = realUrl + "/" + dateStr + endName;
			out = new FileOutputStream(fileName);// 上传文件存放路径
			out.write(outputStream, 0, outputStream.length);
		} catch (Exception e) {
			System.out.println("提示信息:" + this.getClass().getName() + "|"
					+ e.getMessage());
			return "{success:false}";
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					System.out.println("提示:" + e.getMessage());
				}
			}
		}
		return "{success:true}";
	}
   /**
    * 删除文件方法
    * @param filePath
    * @return
    */
	public String deleteFile(String filePath) {
		File file = new File(filePath);
		return file.delete()?"{success:true}":"{success:false}";
	}
}
最近下载更多
1358849392  LV21 2023年11月18日
mengyr  LV3 2022年3月21日
Gustav_1  LV1 2019年5月29日
plushenko  LV1 2019年2月25日
chinafjfzlj  LV31 2018年10月27日
zjjhzjb  LV14 2018年9月13日
十年后  LV15 2018年5月23日
fengyaofei  LV16 2017年12月13日
nan_fan  LV10 2017年7月21日
剑是道  LV9 2017年6月23日
最近浏览更多
mengyr  LV3 2022年3月21日
lizw007  LV10 2022年1月22日
疯狂的爱人  LV11 2021年6月10日
哎呀  LV1 2021年5月15日
爱情戴罪的羔羊  LV7 2021年2月24日
沉醉不知归wd  LV6 2020年8月11日
多吃多占  LV12 2020年6月8日
luolukka  LV8 2020年5月31日
能不能不存在  LV13 2020年5月15日
hola123  LV3 2020年5月14日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友