One step forward and two steps back this feels like... I can't even get the file renaming task verified. I even just copied and pasted someone else's code for that section who for-sure was passing that and it doesn't change the name of the file. What the heck?? So aggravating. I can't imagine what could be wrong.
Okay, for giggles, I just ran it through the validator instead of just running the code. When running the code, it told me, "Cannot rename file (filename)". And yet, the validator accepts it. And... when I print the renamed file's absolute path, it hasn't changed. Uggghhhhh...
package com.codegym.task.task31.task3101;
/*
Iterating through a file tree
2. For each file in the path directory and in all of its subdirectories, do the following:
For each file whose size in bytes is NOT greater than 50, do the following:
All files have the TXT extension.
Use "/" as the path separator.
*/
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
public class Solution {
//1. The main method is passed two arguments as inputs.
//The first argument is path, which is the path to the directory;
//the second is resultFileAbsolutePath, which is the name (full path) of an existing file that will store the result.
public static void main(String[] args) {
//folder = "c:/path/" (for example)
File folder = new File(args[0]);
System.out.println(folder);
File resultFileAbsolutePath = new File(args[1]);
System.out.println(resultFileAbsolutePath.getAbsolutePath());
/*ArrayList<String> filesLessThan50 = new ArrayList<>();
for (File file : folder.listFiles()) {
//if (file.getTotalSpace() <= 50) {
filesLessThan50.add(file.getName());
// }
}*/
/*ArrayList<File> filesLessThan50Files = new ArrayList<>();
for (String fileString : filesLessThan50) {
filesLessThan50Files.add(new File(fileString));
}
//2.1. Sort them by file name in ascending order. Don't include the path when sorting.
//Sorted in ascending order by file name
Collections.sort(filesLessThan50);*/
//2.2. Rename resultFileAbsolutePath to "allFilesContent.txt" (use the FileUtils.renameFile method and FileUtils.isExist if necessary).
File allFilesContent = new File(resultFileAbsolutePath.getParent() + "\\allFilesContent.txt");
FileUtils.renameFile(resultFileAbsolutePath, allFilesContent);
System.out.println(resultFileAbsolutePath.getName() + "dog");
/*try {
//2.3. Sequentially write the contents of each file from step 2.1 to allFilesContent.txt. After the body of each file, write "\n".
//We need to access each file in our filesLessThan50 ArrayList and write their contents to this file.
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(resultFileAbsolutePath));
for(File fileMember : filesLessThan50Files){
FileInputStream fileInputStream = new FileInputStream(fileMember);
BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream));
String line;
while((line = reader.readLine()) != null){
bufferedWriter.write(line);
}
bufferedWriter.write("\n");
fileInputStream.close();
reader.close();
}
bufferedWriter.close();
}catch(IOException e){
e.getMessage();*/
}
}