The task seems to be trivial, that's just having difficulty.

I get the address of the file in the onActivityResult method after which I create it

 File file = new File(data.getData().getPath()); 

The creation is successful, there are no questions. Then I try to rename the file like this:

 File file = new File(data.getData().getPath()); File file2 = new File(data.getData().getPath(),"324234235461.txt"); file1.renameTo(file2); 

Alas, nothing happens. The file is left with the name that was received during the constructor call new File(data.getData().getPath());

  • Permissions stand on the memory? (Stupid, but it happens) - Flippy
  • All possible memory permissions are set - Heaven

1 answer 1

And where is the file name file1 ? Why take the path 2 times?

 Path path = Paths.get(data.getData().getPath()).getParent()); String fileName = path.getFileName().toString(); File from = new File(path, fileName); File to = new File(path,"324234235461.txt"); from.renameTo(to); 

UPD

In the File constructor, you must transfer the folder where this file is located and its name. What do you have in the path variable? Full path to the file? You need the path to the folder (see the code above)

  • This solution from Google, tried to indicate without a path, but simply the name ... did not help either - Heaven
  • Updated the answer, look - Flippy
  • Not sure getPafent will return the path. See also towards getAbsolutePath - Flippy