-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Expand file tree
/
Copy pathstep_1_validate_input.java
More file actions
28 lines (24 loc) · 944 Bytes
/
step_1_validate_input.java
File metadata and controls
28 lines (24 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
/**
* Validates that the input file exists and is readable.
*
* Usage: java step_1_validate_input.java [input_file]
*/
void main(String[] args) throws IOException {
var inputPath = args.length > 0 ? Path.of(args[0]) : Path.of(Constants.CONTRIBUTE_README_FILE);
System.out.println("Step 1: Validating input file...");
System.out.printf("Input file: %s%n", inputPath.toAbsolutePath());
if (!Files.exists(inputPath) || !Files.isReadable(inputPath)) {
System.err.printf("ERROR: File '%s' does not exist or is not readable.%n", inputPath);
System.exit(1);
}
System.out.println("SUCCESS: Input file validation passed!");
var attrs = Files.readAttributes(inputPath, BasicFileAttributes.class);
System.out.printf(
"File size: %d bytes, Last modified: %s%n",
attrs.size(),
attrs.lastModifiedTime()
);
}