| | |
| | | *
|
| | | * @param file
|
| | | * @param lineEnding
|
| | | * @return
|
| | | * @return the string content of the file
|
| | | */
|
| | | public static String readContent(File file, String lineEnding) {
|
| | | StringBuilder sb = new StringBuilder();
|
| | |
| | | }
|
| | | return sb.toString();
|
| | | }
|
| | |
|
| | | /**
|
| | | * Recursively traverses a folder and its subfolders to calculate the total
|
| | | * size in bytes.
|
| | | * |
| | | * @param directory
|
| | | * @return folder size in bytes
|
| | | */
|
| | | public static long folderSize(File directory) {
|
| | | if (directory == null || !directory.exists()) {
|
| | | return -1;
|
| | | }
|
| | | if (directory.isFile()) {
|
| | | return directory.length();
|
| | | }
|
| | | long length = 0;
|
| | | for (File file : directory.listFiles()) {
|
| | | if (file.isFile())
|
| | | length += file.length();
|
| | | else
|
| | | length += folderSize(file);
|
| | | }
|
| | | return length;
|
| | | }
|
| | | }
|