1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8. public class FilePathExtractor {
  9. public static void main(String[] args) {
  10. String configFilePath = "config.txt"; // Replace with your config file path
  11. String outputFilePath = "extracted_paths.txt";
  12. List<String> filePaths = extractFilePaths(configFilePath);
  13. try (java.io.PrintWriter writer = new java.io.PrintWriter(outputFilePath)) {
  14. for (String path : filePaths) {
  15. writer.println(path);
  16. }
  17. } catch (IOException e) {
  18. System.err.println("Error writing to file: " + e.getMessage());
  19. }
  20. }
  21. public static List<String> extractFilePaths(String configFilePath) {
  22. List<String> filePaths = new ArrayList<>();
  23. Map<String, String> configMap = new HashMap<>();
  24. try (BufferedReader reader = new BufferedReader(new FileReader(configFilePath))) {
  25. String line;
  26. while ((line = reader.readLine()) != null) {
  27. // Assuming config format: key=value, where key is the file path
  28. String[] parts = line.split("=");
  29. if (parts.length == 2) {
  30. String key = parts[0].trim();
  31. String value = parts[1].trim(); //value is the file path
  32. configMap.put(key, value);
  33. }
  34. }
  35. } catch (IOException e) {
  36. System.err.println("Error reading config file: " + e.getMessage());
  37. return new ArrayList<>(); // Return empty list if error
  38. }
  39. filePaths.addAll(configMap.values()); // Add all file paths to the list
  40. return filePaths;
  41. }
  42. }

Add your comment