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();
}
}
}
阅读(3144) | 评论(0) | 转发(0) |