import java.io.File; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.alibaba.druid.util.Base64; public class FilesUtils { private static final Logger LOG = LoggerFactory.getLogger(FilesUtils.class); /** * 根据文件绝对地址返回该文件的base64编码 * * @param aFilePath 文件绝对路径 * @return */ public static String getBase64str(String aFilePath) { String re = null; try { File file = new File(aFilePath); if (file.exists()) { re = Base64.byteArrayToBase64(FileUtils.readFileToByteArray(file)); } } catch (Exception e) { LOG.error("read file to byte error", e); } return re; }