import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class LogFileGuard {
private final String logFilePath;
private final String overrideFilePath; // File to store override flag
public LogFileGuard(String logFilePath, String overrideFilePath) {
this.logFilePath = logFilePath;
this.overrideFilePath = overrideFilePath;
}
public boolean isAllowedToWrite() {
Path overridePath = Paths.get(overrideFilePath);
try {
if (Files.exists(overridePath)) {
return true; // Override file exists, allow writing
} else {
return false; // No override, deny writing
}
} catch (IOException e) {
// Handle IO exceptions appropriately, e.g., log the error
System.err.println("Error checking override file: " + e.getMessage());
return false; // Default to denying write access in case of error
}
}
}
Add your comment