io - Java Buffer reader data from text file with comma manipulation -
i'm new java programming , i'm challenging myself 1 seems when comes buffer reader , writer lost. have 2 text file parsing out csv file, , want compare data between textfile.
this looks inside text file.
file1.text sample1,true,online file2.text sample1,true,test,check,ol expected output : valid file3.text online,ol offline,of idle, il i want compare online in file1 , ol in file2. can see seperated comma. if online word in file1 change offline or idle output should invalid , same on file2. in advance guys!any appreciated. cheers
here points.
file3 looks candidate extract map<k, v>, place first value key , second value.
read file1 , file2 lines , split them comma. like:
try (bufferedreader br = new bufferedreader(new filereader(file))) { string line; while ((line = br.readline()) != null) { string[] values = line.split(","); // extract values indexes , use created map file3 validate input. } } validation logic:
map<string, string> map; // assuming populate file3 content , contains online->ol, offline->of etc. ; void validate(string valuefromfile1, string valuefromfile2) { if (map.containskey(valuefromfile1) && map.get(valuefromfile1).equals(valuefromfile2)) { // valid; } else { // invalid }
Comments
Post a Comment