import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
public class FilePathExtractor {
public static void main(String[] args) {
String configFilePath = "config.txt"; // Replace with your config file path
String outputFilePath = "extracted_paths.txt";
List<String> filePaths = extractFilePaths(configFilePath);
try (java.io.PrintWriter writer = new java.io.PrintWriter(outputFilePath)) {
for (String path : filePaths) {
writer.println(path);
}
} catch (IOException e) {
System.err.println("Error writing to file: " + e.getMessage());
}
}
public static List<String> extractFilePaths(String configFilePath) {
List<String> filePaths = new ArrayList<>();
Map<String, String> configMap = new HashMap<>();
try (BufferedReader reader = new BufferedReader(new FileReader(configFilePath))) {
String line;
while ((line = reader.readLine()) != null) {
// Assuming config format: key=value, where key is the file path
String[] parts = line.split("=");
if (parts.length == 2) {
String key = parts[0].trim();
String value = parts[1].trim(); //value is the file path
configMap.put(key, value);
}
}
} catch (IOException e) {
System.err.println("Error reading config file: " + e.getMessage());
return new ArrayList<>(); // Return empty list if error
}
filePaths.addAll(configMap.values()); // Add all file paths to the list
return filePaths;
}
}
Add your comment