简体   繁体   English

将文件从目录移动到另一个目录后如何保存文件路径

[英]how to save file path after move it from a directory to another in java

I copy a file from a directory for another but I have a difficulty to find the new file path ! 我从另一个目录复制文件,但是很难找到新文件路径! I used FileUtils class from apache commons-io library to do that..... please is that there a function can save the last file path ? 我使用apache commons-io库中的FileUtils类来做到这一点.....请问是否有一个函数可以保存最后一个文件路径?

Since FileUtils.moveFile accepts two arguments -- source file and destination file, all you need to do is to use second arg: 由于FileUtils.moveFile接受两个参数-源文件和目标文件,所以您要做的就是使用第二个arg:

File myFile = new File("file");
File newLocation = new File("funky_file");
FileUtils.copyFile(myFile, newLocation);
myFile = newLocation;

You cannot retrive new location basing only on myFile without reassigning: File class is designed to be a immutable path rather that hard link to the file. 您不能在不重新分配的情况下仅基于myFile检索新位置:File类设计为不可变路径,而不是指向文件的硬链接。

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

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