Question
I need help to rewrite below Java code to write into txt file all records belonging to src2. package FileProcessing; import java.io.BufferedReader; import java.io.BufferedWriter; import
I need help to rewrite below Java code to write into txt file all records belonging to src2.
package FileProcessing;
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException;
public class FileProcessing {
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\\sampleFile.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 if (checkEligibleTrnRec(ftn_recs)) { // If the record is eligible, write it to the output file f2.write(ftn_recs + " "); // Increment the counter for eligible transaction records 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[] src2 = {"AES", "CCX", "CIF", "MSB", "PTT", "SEI", "TD1", "TD2", "TD3", "TSP", "TSX", "PAP", "USR"};
// Check if the source system is in the second array if (chk_rec_sep.length > 2 && containsIgnoreCase(src2, chk_rec_sep[2])) { // The record is eligible, return true return true; }
// The record is not eligible, return false return false; }
public static boolean containsIgnoreCase(String[] arr, String str) { for (String s : arr) { if (s.equalsIgnoreCase(str)) { return true; } } return false; } }
Below is the sample file with 3 records for CCX, CIF, and Y28. I only need all information related to CCX and CIF to be printed out into new text file. Attached screenshot below sample output file as well.
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 : CCX 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 ------------------------------------------------------------------------------------------------------------------------------------
F21120707112912346 .000 CIF AUTO HOLD 07 DEC 24 09:11:32 89.0 85.0 101.0 SYSTEM CIF
F21120707112912346 - Transaction Details:
Format type : U Request type : S Criteria Set : Transaction Location : CIF 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
F21120707112912346 - 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 ------------------------------------------------------------------------------------------------------------------------------------
I want the new text file to be as below. Exclude all transactions that aren't in src2 "AES", "CCX", "CIF", "MSB", "PTT", "SEI", "TD1", "TD2", "TD3", "TSP", "TSX", "PAP", "USR"
Fe112a7a7112912345 - Natch 1 [Field Based Scanning Risk Entity Natch] F21129797112912345 .699 CIF AUTO HOLO 67 DEC 24 e9:11:32 89.e 85.0 1e1.e SYSTEM CIF F211297a7112912345 - Transaction Details: Free farm: [FULL_NRE] WOGHERRN, ISNAIL AHNAOI [AOORESS] [AOORESS2] [CITY_STATE] [PAONINCE] [COUNTRY] [GATE_OF_BIRTH] [101] TITESTezeaen [ LINE ]2 F2112a7a7112912345 - Natch 1 [Field Based Scanning Risk Entity Natch] * Name : mogreaen, ismail AHNeOI Address City/state country Origin Accuity Risk Entity Comments : AOOITIONAL SANCTIONS INFOANATION-SUBJECT TO SECONDARY SANCTIONS Title : HEPO OF IRANIAN POLICE ESNAIL; AHNOI-MOQCOOR, ESNA'IL; MOGHROOEN, ESENEEL AHNAOI; MOGHOOOEM, ISNAIL AHNAOI Risk Entity Info : 467916 Additional information 1: : 13 Additional information 2 : SYRIA \& IRAN-HR \& IRAN-TRA Additional information 3:66/69/2011a/a/az/2913 Additional information 4 Additional information 5 Additional information 6: CHIEF, IRAN'S LeW ENFORCENENT FOACES; POLICE CHIEF; CONVANDER OF IRAN'S LAW ENFOACENENT FOACE; BRIGPOIER GENERAL Additional information 7 Additional information 8 Additional information 9 Additional information 10 Froe form Natch Text : Mogyegen, IsNaIL AHvel
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started