【问题标题】:Android rename retrieved image fileAndroid重命名检索到的图像文件
【发布时间】:2016-06-27 06:33:46
【问题描述】:

我有一个图片路径,比如说

/storage/emulated/0/PurTab/2148094.jpg

我想将此图像归档并将其重命名为 XYZ.jpg 并将其放入文件中。

我尝试的是

//get file
File photo = new File(baseApp.getObserver().getTempImageFilePath());

//resave file with new name
File newFile = new File("XYZ.jpg");
photo.renameTo(newFile);

但不工作。 这该怎么做..... ??

【问题讨论】:

    标签: android image file


    【解决方案1】:

    首先你检查你的 AndroidManifest 权限:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

    AndroidManifest 文件中需要这两个权限。

    如果这两个权限在您的 AndroidManifest 中都可用,则检查您的更改文件是否存在。

    if(photo.exist())
    {
    -- change file name logic
    }
    

    比改变你的文件名就完成了。

    【讨论】:

      猜你喜欢
      • 2012-11-11
      • 1970-01-01
      • 2022-11-30
      • 2018-12-20
      • 1970-01-01
      • 2011-01-01
      • 1970-01-01
      • 2022-11-13
      • 2012-04-07
      相关资源
      最近更新 更多