任务看似微不足道,实则难度不小。
我在方法中收到文件的地址,onActivityResult然后创建它
File file = new File(data.getData().getPath());
创建成功,没有问题。然后我尝试像这样重命名文件:
File file = new File(data.getData().getPath());
File file2 = new File(data.getData().getPath(),"324234235461.txt");
file1.renameTo(file2);
las,什么也没有发生。该文件保留在调用构造函数期间收到的名称new File(data.getData().getPath());
文件名在哪里
file1?为什么要走 2 次路径?更新程序
在构造函数中,
File您需要传递此文件所在的文件夹及其名称。你在变量中有path什么?文件的完整路径?您需要文件夹的路径(请参阅上面的代码)