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

Add your comment