Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1750376
  • 博文数量: 600
  • 博客积分: 10581
  • 博客等级: 上将
  • 技术积分: 6205
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-06 10:13
文章分类
文章存档

2016年(2)

2015年(9)

2014年(8)

2013年(5)

2012年(8)

2011年(36)

2010年(34)

2009年(451)

2008年(47)

分类: Java

2009-01-09 17:52:01


public class FileUtil {
 public static File saveFile(String fileContent, String filePath)
   throws IOException {
  if (fileContent == null) {
   return null;
  }
  BASE64Decoder decoder = new BASE64Decoder();
  byte[] picBinary = decoder.decodeBuffer(fileContent);
  File file = new File(filePath);
  FileOutputStream out = new FileOutputStream(file);
  out.write(picBinary);
  out.close();
  return file;
 }
 public static String readFile(String filePath) {
  try {
   BASE64Encoder encoder = new BASE64Encoder();
   File file = new File(filePath);
   FileInputStream in = new FileInputStream(file);
   byte[] b = new byte[(int) file.length()];
   in.read(b);
   String result =encoder.encode(b);
   in.close();
   return result;
  } catch (Exception e) {
   
   e.printStackTrace();
  }
  return null;
 }
 
 public static void deleteFile(String fileName) {
  File file = new File(fileName);
  if (file.exists() && file.isFile()) {
   file.delete();
  }
 }
}
阅读(3016) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~