1. import java.io.File;
  2. import java.io.IOException;
  3. import java.nio.file.Files;
  4. import java.nio.file.Path;
  5. import java.nio.file.Paths;
  6. public class LogFileGuard {
  7. private final String logFilePath;
  8. private final String overrideFilePath; // File to store override flag
  9. public LogFileGuard(String logFilePath, String overrideFilePath) {
  10. this.logFilePath = logFilePath;
  11. this.overrideFilePath = overrideFilePath;
  12. }
  13. public boolean isAllowedToWrite() {
  14. Path overridePath = Paths.get(overrideFilePath);
  15. try {
  16. if (Files.exists(overridePath)) {
  17. return true; // Override file exists, allow writing
  18. } else {
  19. return false; // No override, deny writing
  20. }
  21. } catch (IOException e) {
  22. // Handle IO exceptions appropriately, e.g., log the error
  23. System.err.println("Error checking override file: " + e.getMessage());
  24. return false; // Default to denying write access in case of error
  25. }
  26. }
  27. }

Add your comment