import java.io.*;
import java.util.Properties;
public class DataTruncator {
private static final String CONFIG_FILE = "config.properties";
private static int maxRecordLength = 0;
public static void main(String[] args) {
try {
loadConfiguration();
truncateData();
} catch (IOException e) {
System.err.println("Error: " + e.getMessage());
}
}
private static void loadConfiguration() throws IOException {
Properties props = new Properties();
try (FileInputStream fis = new FileInputStream(CONFIG_FILE)) {
props.load(fis);
maxRecordLength = Integer.parseInt(props.getProperty("maxRecordLength"));
}
}
private static void truncateData() throws IOException {
// Simulate reading data from a source
String[] data = {"This is a very long string that needs to be truncated.",
"Another long string for testing the truncation.",
"Short string"};
for (String record : data) {
if (record.length() > maxRecordLength) {
String truncatedRecord = record.substring(0, maxRecordLength) + "..."; // Truncate and add ellipsis
System.out.println("Original: " + record);
System.out.println("Truncated: " + truncatedRecord);
} else {
System.out.println("Original: " + record);
System.out.println("Truncated: " + record); // No truncation needed
}
}
}
}
Add your comment