删除图片后,更新系统相册
public void deleteVideoInSystem(String paths) {
String where=MediaStore.Audio.Media.DATA+" like \""+paths+"%"+"\"";
//图片
mContext.getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,where,null);
//视频
mContext.getContentResolver().delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,where,null);
}
/**
* 判断文件是否存在
* */
public boolean fileIsExists(String strFile) {
try {
File f=new File(strFile);
if(!f.exists()) {
return false;
}
}
catch (Exception e) {
return false;
}
return true;
}
/**
* 根据目录删除所有的文件
*
* @param filePath
*/
public static void deleteFileByPath(String filePath) {
File rootfile = new File(filePath);
if (rootfile != null && rootfile.exists()) {
if (rootfile.isDirectory()) {
File[] files = rootfile.listFiles();
if (files != null) {
for (File childFile : files) {
deleteFileByPath(childFile.getAbsolutePath());
}
}
rootfile.delete();
} else if (rootfile.isFile()) {
rootfile.delete();
}
}
}
/**
* 删除文件
* @param path
*/
public static void deleteFile(String path){
File file = new File(path);
if (file.exists()) {
file.delete();
}
}
/**
* 获取某个文件或者目录的大小
*
* @param f
* @return
*/
public static long getFileSize(File f) {
long size = 0;
if (f.exists()) {
if (f.isDirectory()) {
File flist[] = f.listFiles();
if (flist != null) {
for (int j = 0; j < flist.length; j++) {
if (flist[j].isDirectory()) {
size = size + getFileSize(flist[j]);
} else {
size = size + flist[j].length();
}
}
}
} else {
size = f.length();
}
}
return size;
}
获取文件列表
public static List<String> getFileList(File f) {
List<String> list = new ArrayList<>();
if (f.exists()) {
if (f.isDirectory()) {
File flist[] = f.listFiles();
if (flist != null) {
for (int j = 0; j < flist.length; j++) {
if (flist[j].isDirectory()) {
list.addAll(getFileList(flist[j]));
} else {
list.add(flist[j].getAbsolutePath());
}
}
}
} else {
list.add(f.getAbsolutePath());
}
}
return list;
}
/**
* 文件大小格式化
* @param size 单位为B、kb、mb、gb转换
* @return
*/
public static String byteToFormat(long size){
long kb = 1024;
long mb = kb*1024;
long gb = mb*1024;
if (size >= gb){
return BigDecimalUtils.div(size+"",gb+"",2)+"GB";
}else if (size >= mb){
return BigDecimalUtils.div(size+"",mb+"",2)+"MB";
}else if (size > kb){
return BigDecimalUtils.div(size+"",kb+"",2)+"KB";
}else {
return BigDecimalUtils.div(size+"",1+"",2)+"B";
}
}
Android 判断文件是否存在、文件删除文件、文件大小file,删除图片、视频后更新系统相册
最新推荐文章于 2024-08-12 03:56:54 发布