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 EnvironmentPreparer {
/**
* Creates a simple isolated environment directory structure.
* @param envDir The directory where the isolated environment will be created.
* @param filesToCreate An array of file names to create within the environment.
* @throws IOException If an error occurs during file creation.
*/
public static void prepareEnvironment(String envDir, String[] filesToCreate) throws IOException {
File envDirFile = new File(envDir);
if (!envDirFile.exists()) {
envDirFile.mkdirs(); // Create the directory if it doesn't exist
}
for (String fileName : filesToCreate) {
Path filePath = Paths.get(envDir, fileName);
Files.createFile(filePath); // Create each file
}
}
public static void main(String[] args) throws IOException {
String environmentDirectory = "isolated_env"; // Define the environment directory
String[] files = {"config.txt", "data.json", "logs/app.log"}; // Define files to create
prepareEnvironment(environmentDirectory, files);
System.out.println("Isolated environment created successfully.");
}
}
Add your comment