Question: I need ot rewrite below Java code to write into txt file only src2 records. public static void main(String[] args) { // Input and output

I need ot rewrite below Java code to write into txt file only src2 records.

public static void main(String[] args) { // Input and output file paths String fi = "C:\\Users\\mua2643\\OneDrive - MUFG Union Bank\\MUB_Dedicated\\FileProcessingApproach3\\src\\FileProcessing\\one_MB_test_file.txt"; String fo = fi + ".data.txt"; // Counter for eligible transaction records int rec_cnt = 0;

try (BufferedReader f1 = new BufferedReader(new FileReader(fi)); BufferedWriter f2 = new BufferedWriter(new FileWriter(fo, true))) { String ftn_recs; // Read each line from input file while ((ftn_recs = f1.readLine()) != null) { // Check if the transaction record is eligible boolean is_eligible = checkEligibleTrnRec(ftn_recs); // If the record is eligible, write it to the output file if (is_eligible) { f2.write(ftn_recs + " "); rec_cnt++; } } // Write the total count of eligible transaction records to the output file String write_trn_rec_cnt = "Total Count : " + rec_cnt + " "; f2.write(write_trn_rec_cnt); } catch (IOException e) { e.printStackTrace(); } }

// Method to check if a transaction record is eligible public static boolean checkEligibleTrnRec(String chk_rec) { // Split the transaction record by spaces String[] chk_rec_sep = chk_rec.split("\\s+"); // Array of source systems that indicate if a transaction record is eligible or not String[] src1 = {"Y28", "D69", "NYB", "WKD"}; String[] src2 = {"AES", "CCX", "CIF", "MSB", "PTT", "SEI", "TD1", "TD2", "TD3", "TSP", "TSX", "PAP", "USR"};

// Check if the source system is in the second array for (String src_i : src2) { // If the source system occurs more than once and its code is in the third position if (countOccurrences(chk_rec_sep, src_i) > 1 && chk_rec_sep[2].equals(src_i)) { // The record is eligible, return true return true; } } // The record is not eligible, return false return false; } public static int countOccurrences(String[] arr, String val) { int count = 0; for (String s : arr) { if (s.equals(val)) { count++; } } return count; }

Below is the sample record for Y28 and CCX, but I only need all information related to src2 "AES", "CCX", "CIF", "MSB", "PTT", "SEI", "TD1", "TD2", "TD3", "TSP", "TSX", "PAP", "USR" and write into new text file.

Date: 23 SEP 20 Time: 8:40 Transaction Report

TRANSACTION NUMBER AMOUNT CNCY SVC DISPOSITION DATE/TIME % PT FT USER LOC ------------------------------------------------------------------------------------------------------------------------------------ F01120707112912345 .000 CCX AUTO HOLD 07 DEC 24 09:11:32 89.0 85.0 101.0 SYSTEM CCX

F01120707112912345 - Transaction Details:

Format type : U Request type : S Criteria Set : Transaction Location : CIF Rule Based Scanning : Applied ------------------------------------------------------------------------------------------------------------------------------------ Free Form: [ID]TEST01ADAM 1* 2* 3* 4* 5* 6* 7* 8* [FULL_NAME]ESAH, WALI ADAM [ADDRESS] [ADDRESS2] [CITY_STATE] [PROVINCE] [COUNTRY] [DATE_OF_BIRTH] [ID1]||TEST01ADAM [LINE]1

F01120707112912345 - Match 1 [Field Based Scanning Risk Entity Match] ------------------------------------------------------------------------------------------------------------------------------------ * Name : ESAH, WALI ADAM Address : LAHORE CITY City/State : LAHORE DISTRICT Country : PK Origin : ACCUITY Risk Entity Comments : Title : MAULANA Remarks : ALVI, MOHAMMAD MASOOD AZHAR Risk Entity Info : 407910 Additional information 1 : 07/10/1968 03 Additional information 2 : SDGT Additional information 3 : 11/04/2010 05/30/2019 Additional information 4 : Additional information 5 : PAKISTAN PUNJAB PROVINCE Additional information 6 : 407904 Additional information 7 : Additional information 8 : PAKISTAN Additional information 9 : PAKISTAN Additional information 10 : STRONG Free Form Match Text : ESAH, WALI ADAM ------------------------------------------------------------------------------------------------------------------------------------

F01120707112912346 .000 Y28 AUTO HOLD 07 DEC 24 09:11:32 89.0 85.0 101.0 SYSTEM Y28

F01120707112912346 - Transaction Details:

Format type : U Request type : S Criteria Set : Transaction Location : CCX Rule Based Scanning : Applied ------------------------------------------------------------------------------------------------------------------------------------ Free Form: [ID]TEST02ADAM 1* 2* 3* 4* 5* 6* 7* 8* 9* 10* 11* 12* 13* 14* 15* 16* 17* [FULL_NAME]MOGHADAM, ISMAIL AHMADI [ADDRESS] [ADDRESS2] [CITY_STATE] [PROVINCE] [COUNTRY] [DATE_OF_BIRTH] [ID1]||TEST02ADAM [LINE]2

F01120707112912346 - Match 1 [Field Based Scanning Risk Entity Match] ------------------------------------------------------------------------------------------------------------------------------------ * Name : MOGHADAM, ISMAIL AHMADI Address : City/state : Country : Origin : ACCUITY Risk Entity Comments : ADDITIONAL SANCTIONS INFORMATION -SUBJECT TO SECONDARY SANCTIONS Title : HEAD OF IRANIAN POLICE Remarks : AHMADI MOGHADAM, ISMAIL; AHMADI MOGHADDAM, ESMA'IL; AHMADI-MOGHADDAM, ESMA'IL; AHMADI-MOGHADDAM, ESMAIL; AHMADI-MOQADDAM, ESMA'IL; MOGHADDAM, ESAMEEL AHMADI; MOGHADDAM, ISMAIL AHMADI Risk Entity Info : 467916 Additional information 1 : 03 Additional information 2 : SYRIA & IRAN-HR & IRAN-TRA Additional information 3 : 06/09/2011 07/02/2013 Additional information 4 : Additional information 5 : Additional information 6 : CHIEF, IRAN'S LAW ENFORCEMENT FORCES; POLICE CHIEF; COMMANDER OF IRAN'S LAW ENFORCEMENT FORCE; BRIGADIER GENERAL Additional information 7 : Additional information 8 : Additional information 9 : Additional information 10 : Free Form Match Text : MOGHADAM, ISMAIL AHMADI ------------------------------------------------------------------------------------------------------------------------------------

Below is the sample output I am expecting for CCX to be written in txt file

I need ot rewrite below Java code to write into txt file

Date: 23 SEP 20 Time: 8:40 Transaction Report TRANSACTION NUMBER AMOUNT CNCY SVC DISPOSITION DATE/TIME % PT FT USER LOC F01120707112912345 .000 CCX AUTO HOLD 07 DEC 2409:11:32 89.085.0101.0 SYSTEM CCX F01120707112912345 - Transaction Details: Free Form: [ID] TEST01ADAM 1* 2* 3*4* 5*6* 7* 8* [FULL_NAME]ESAH, WALI ADAM [ADDRESS] [ADDRESS2] [CITY_STATE] [PROVINCE] [COUNTRY] [DATE_OF_BIRTH] [ID1] TESTO1ADAM [LINE] 1 F01120707112912345 - Match 1 [Field Based Scanning Risk Entity Match] * Name : ESAH, WALI ADAM Address : LAHORE CITY City/State : LAHORE DISTRICT Country : P PK Origin : ACCUITY RiskEntityCommentsTitle::MAULANA Remarks : ALVI, MOHAMMAD MASOOD AZHAR Risk Entity Info : 407910 Additional information 1:07/10/196803 Additional information 2: SDGT Additional information 3:11/04/201005/30/2019 Additional information 6407904 Additional information 7 Additional information 8: PAKISTAN Additional information 9: PAKISTAN Additional information 10: STRONG Free Form Match Text : ESAH, WALI ADAM

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!