简体   繁体   English

重命名文件并再次覆盖

[英]Rename file and overwrite it again

I'm trying to rename file on my gallery I'm using following steps 我正在尝试使用以下步骤重命名画廊中的文件

getting file path from device then rename the path , but it doesn't rename it on local path 从设备获取文件路径,然后重命名路径,但是它不会在本地路径上重命名

I want to overwrite it with new name 我想用新名称覆盖它

             picturePath = cursor.getString(columnIndex);// real pic path on my device after getting it from gallery 
         File photo = new File(picturePath);
         File newFile= new File(picturePath,"hhhhhhh");
         photo.renameTo(newFile);

If picturePath is the complete path (path+filename), then on the second call you are trying to define the newFile object as (path+filename+newname). 如果picturePath是完整路径(path + filename),则在第二次调用时,您尝试将newFile对象定义为(path + filename + newname)。 Eg you have /some/where/photo.jpg and renaming it to /some/where/photo.jpg/hhhhhhh. 例如,您拥有/some/where/photo.jpg并将其重命名为/some/where/photo.jpg/hhhhhhh。 I guess you need a getPath() there. 我猜你在那里需要一个getPath()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM