从/data/data/com.example.../files/删除文件

时间:2017-02-05 21:51:31

标签: java android file

我有一个程序可以将图像保存在app文件目录中,以及它到数据库的绝对路径:

The compiler can decide that an int will a 71 bit number stored in a 128 bit memory space where the additional 57 bits are used to store the programmers girlfriends birthday.

将图像显示到ImageView中可以正常工作。无论如何,现在我想删除它们。这是一个路径示例:/data/data/com.example.facu.dbproperty/files/imagenes/1-mkpb3smpf7h0v

 DBHelperPropiedades db = new DBHelperPropiedades(this);

    //Si retorna una imagen
    if (requestCode == PICK_IMAGE && resultCode == Activity.RESULT_OK) {
        if (data == null) { //Si esta vacio
            //Display an error
            return;
        }
        try { //Agrega la imagen

            //Crea la carpeta donde se guarda la imagen, si no existe
            InputStream isImg = this.getContentResolver().openInputStream(data.getData());
            //db.IMAGES_DIR es una cadena con valor "imagenes"
            File dir = new File(this.getFilesDir(),db.IMAGES_DIR);
            dir.mkdirs();

            //Coloca el nombre a la imagen (id+random)
            String imgName=idPropiedad+"-";
            imgName+=new BigInteger(20, new SecureRandom()).toString(32);

            //Obtiene el Output para la imagen
            File imgFile = new File(dir, imgName);
            FileOutputStream osImg = new FileOutputStream(imgFile);

            //Copia la imagen
            byte[] buf = new byte[1024];
            int len;
            while ((len = isImg.read(buf)) > 0) {
                osImg.write(buf, 0, len);
            }

            //Cierra los stream
            isImg.close();
            osImg.close();

            //Guarda la URL y la foreingKey en la base de datos
            String uriImg=imgFile.getAbsolutePath();
            if(!db.addImagen(idPropiedad, uriImg)){
                Toast.makeText(this, "Carga en Base de datos Fallida", Toast.LENGTH_SHORT).show();
            }

        } catch (IOException e) {
            //Error
        }

但imgFile.exists()是假的,即使我可以在ImageView中使用它。

据此:Deleting files from applications data folderhttps://es.stackoverflow.com/questions/37108/c%c3%b3mo-acedo-a-la-carpeta-data-data-my-package-com-desde-android-por-medio-de-c%c3%b3(西班牙语),这是一个许可问题......但我找不到解决方案......

所以...我怎么能解决这个问题,从我的实际路径中删除文件(/ data / data ..),或者如何保存图像(在安全目录中,防止删除),并显示/现在删除它们......

0 个答案:

没有答案
相关问题