//文件转换为String
public static String FiletoString(String path){
String string=null;
try {
File file = new File(path);
FileInputStream inputFile = new FileInputStream(file);
byte[] buffer = new byte[(int)file.length()];
inputFile.read(buffer);
inputFile.close();
string=Base64.encodeToString(buffer,Base64.DEFAULT);
} catch (Exception e) {
string=null;
}
return string;
}
//String 转换为文件
public static void StringtoFile(String base64Code,String savePath) {
try {
byte[] buffer =Base64.decode(base64Code, Base64.DEFAULT);
FileOutputStream out = new FileOutputStream(savePath);
out.write(buffer);
out.close();
} catch (Exception e) {
// TODO: handle exception
}
}
public static String FiletoString(String path){
String string=null;
try {
File file = new File(path);
FileInputStream inputFile = new FileInputStream(file);
byte[] buffer = new byte[(int)file.length()];
inputFile.read(buffer);
inputFile.close();
string=Base64.encodeToString(buffer,Base64.DEFAULT);
} catch (Exception e) {
string=null;
}
return string;
}
//String 转换为文件
public static void StringtoFile(String base64Code,String savePath) {
try {
byte[] buffer =Base64.decode(base64Code, Base64.DEFAULT);
FileOutputStream out = new FileOutputStream(savePath);
out.write(buffer);
out.close();
} catch (Exception e) {
// TODO: handle exception
}
}