Tag: android external storage

Android 4.4.2不删除文件

我有一堆代码扫描目录中的所有文件,它应该删除这些文件。 但出于某种原因,它并没有删除它们。 我有的是这个: String path = Environment.getExternalStorageDirectory().getAbsolutePath()+”/Images/”; File f = new File(path); File file[] = f.listFiles(); for (File aFile : file) { boolean isDeleted = aFile.delete(); if(isDeleted) { log.d(“file”, “is deleted”); } } 当我调试这个代码时,它会说每个isDeleted文件都是true 。 但当我检查手机上的“图库/图像”文件夹时,我发现所有图像仍然存在… 我的清单中还有以下两个权限: 任何人都知道为什么文件没有删除,尽管它说isDeleted是true吗?

android java.io.File.fixSlashes(File.java:185)

我在控制台崩溃和anrs中出错了。 有时会出现此错误,我无法找到问题所在。 java.lang.NullPointerException at java.io.File.fixSlashes(File.java:185) at java.io.File.(File.java:134) 保存图片的function代码是: public static String sharePhoto(Context context, Bitmap bmp) { File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + “/Pictures/Folder”); boolean success = true; String file_path = null; if (!folder.exists()) { success = folder.mkdir(); } if (success) { file_path = folder + “/Img_” + System.currentTimeMillis() / 1000 + “.jpg”; } OutputStream os […]

在Android中将文件从内部存储复制到外部存储

我的应用程序( Android API 15 )制作图片并将其存储在内部存储器的文件夹中。 现在,我想将此文件复制到外部存储器内的另一个文件夹,例如/sdcard/myapp 。 我尝试了以下方法: 方法#1: private void copyFile(File src, File dst) throws IOException { File from = new File(src.getPath()); File to = new File(dst.getPath()); from.renameTo(to); } 方法#2: private void copyFile(File src, File dst) throws IOException { FileChannel inChannel = null; FileChannel outChannel = null; try { inChannel = new FileInputStream(src).getChannel(); outChannel […]