public String base64() {
String url = "D:" + File.separator + "date" + File.separator ;
String base64Code = null;
try {
System.out.println(url + "13066.mp3");
base64Code = base64Config.encodeBase64File(url+ "13066.mp3");
} catch (Exception e) {
e.printStackTrace();
System.out.println("转base64字符串失败");
}
return base64Code;
}
public static void base64ToFile(String base64, String fileName, String savePath) {
File file = null;
String filePath = savePath;
File dir = new File(filePath);
if (!dir.exists() && !dir.isDirectory()) {
dir.mkdirs();
}
BufferedOutputStream bos = null;
java.io.FileOutputStream fos = null;
try {
byte[] bytes = Base64.getMimeDecoder().decode(base64);
file=new File(filePath + fileName);
fos = new java.io.FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(bytes);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH )+1;
String months = month <10 ? "0" + month : month + "";
String url = "D:" + File.separator + "date" + File.separator + year + "_" + months + File.separator;
String base64 = this.base64();
base64ToFile(base64,"xxx.mp3",url);