import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class SandboxConfigFilter {
public static void main(String[] args) {
String configFilePath = args[0]; // Get config file path from command line
String sandboxConfig = filterForSandbox(configFilePath);
System.out.println(sandboxConfig); // Output the filtered configuration
}
public static String filterForSandbox(String configFilePath) {
StringBuilder sandboxConfig = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new FileReader(configFilePath))) {
String line;
boolean inSandboxSection = false;
while ((line = reader.readLine()) != null) {
line = line.trim(); // Remove leading/trailing whitespace
if (line.startsWith("[sandbox]")) {
inSandboxSection = true;
sandboxConfig.append(line).append("\n"); // Add sandbox section header
} else if (inSandboxSection) {
// Only include lines within the [sandbox] section
if (!line.isEmpty() && !line.startsWith("#")) { //skip empty lines and comments.
sandboxConfig.append(line).append("\n");
}
}
}
} catch (IOException e) {
System.err.println("Error reading config file: " + e.getMessage());
return ""; //Return empty string on error
}
return sandboxConfig.toString();
}
}
Add your comment