101k views
4 votes
I need Java code to read data for source system from properties file. Please help to re-write below code to read data for source system from properties file.

Properties fileProp = new Properties();
fileProp.load(new FileInputStream("properties/fileProcessing.ini"));

// Array of source systems that indicate if a transaction record is eligible or not
String[] source_system_comingled = {"Y28", "D69", "NYB", "WKD"};
String[] source_system_MUB = {"AES", "CCX", "CIF", "MSB", "PTT", "SEI", "TD1", "TD2", "TD3", "TSP", "TSX", "PAP", "USR"};

Below is the sample properties file.

I want source_system_MUB to be read from properties file. Please don't use org.ini4j.Ini library use java.util.Properties.

User Paxic
by
8.2k points

1 Answer

1 vote

Final answer:

To read an array of source systems from a properties file in Java, use the java.util.Properties class to load the file, and then retrieve the property as a string and split it into an array.

Step-by-step explanation:

You want to read the array of source systems from a properties file in Java without using the org.ini4j.Ini library. Instead, you can use the java.util.Properties class to achieve this. Below is the modified code that reads the source_system_MUB from a properties file:

Properties fileProp = new Properties();
fileProp.load(new FileInputStream("path/to/your/fileProcessing.properties"));

String source_systems_MUB = fileProp.getProperty("source_system_MUB");
String[] source_system_MUB = source_systems_MUB.split(",");

Ensure that your fileProcessing.properties file includes a line like the following to define the source_system_MUB:

source_system_MUB=AES,CCX,CIF,MSB,PTT,SEI,TD1,TD2,TD3,TSP,TSX,PAP,USR
This will read the comma-separated values and split them into an array. Do not forget to handle exceptions properly in the actual code to deal with situations where the file might not exist or content cannot be read due to permission issues.

User Viktor Svub
by
7.1k points