devutility.internal.io.FileUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of devutility.internal Show documentation
Show all versions of devutility.internal Show documentation
Utilities for Java development
package devutility.internal.io;
import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Path;
public class FileUtils {
public static boolean exists(String fileName) {
File file = new File(fileName);
return file.exists();
}
public static long getBytesLength(File file) {
if (!file.exists()) {
return 0;
}
return file.length();
}
public static long getBytesLength(Path path) {
File file = path.toFile();
return getBytesLength(file);
}
public static long getBytesLength(String fileName) {
File file = new File(fileName);
return getBytesLength(file);
}
public static String getHourLogFileName(int hour) {
return String.format("%d.log", hour);
}
public static String getFileExtension(String fileName) {
int index = fileName.lastIndexOf(".");
return fileName.substring(index);
}
/**
* Create an new File object.
* @param filePath: File path.
* @return File
* @throws FileNotFoundException When file not found.
*/
public static File create(String filePath) throws FileNotFoundException {
File file = new File(filePath);
if (!file.exists()) {
throw new FileNotFoundException(String.format("File %s not found!", filePath));
}
return file;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy