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 LV15
2018年9月13日
十年后 LV15
2018年5月23日
fengyaofei LV16
2017年12月13日
nan_fan LV10
2017年7月21日
剑是道 LV9
2017年6月23日