package com.mridul.software.automation.spring.context.utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Component;
import java.io.File;
@Slf4j
@Component
public class FileSystemUtils {
public void deleteFileIfExistsAndReCreate(final String fileName) {
try {
deleteFileIfExists(fileName);
FileUtils.touch(new File(fileName));
} catch (final Exception e) {
log.debug("File {} could not be created due to {}", fileName, e);
}
}
public void deleteFileIfExists(final String fileName) {
try {
File file = new File(fileName);
if (file.exists()) {
org.springframework.util.FileSystemUtils.deleteRecursively(file);
log.debug("Delete file : {}", fileName);
}
} catch (final Exception e) {
log.debug("File {} could not be created due to {}", fileName, e);
}
}
}
Comments
Post a Comment