Good evening. 3 days already trying to figure out how to move files in java. There is a task: to read the list of files from the specified directory, sort by the word entered from the keyboard and move the sorted files to the specified directory. This method returns a list of files from the directory.
public static String[] getFilesList(File fl) { String[] listFiles = fl.list(); for (int i = 0; i < listFiles.length; i++) { } return listFiles; } Next, the cycle sorting is implemented:
for (int i = 0; i < arr.length; i++) { if (arr[i].indexOf(inpFilterName) > 0) And now the biggest problem - in the same cycle I want to immediately move the files to the specified path. Google prompted to use the renameTo () method of the File class. I tried to implement it like this:
File dir = new File(); dir.renameTo() But I cannot understand what to pass to it as an argument, and will it work if we have a file name as input and not a file? In general, I am completely confused and really looking forward to help!