java - How can I select string after = operator in a file? -
i have file containing following text:
companyname=ibm name=user1234 companyname=google
how can check if text 'companyname' exists in text file, if select string after = operator?. text above file should output ibm , google.
while ((line = br.readline()) != null) { system.out.println(line); }
would this?
while ((line = br.readline()) != null) { system.out.println(line); if(line.contains("companyname")) { string[] splits = line.split("="); string desired = splits[1]; // second position in string array. } }
edit: adding more functionality in getting other fields @ same time.
while ((line = br.readline()) != null) { system.out.println(line); string compname = ""; string name = ""; if(line.contains("companyname")) { string[] splits2 = line.split("="); compname = splits2[1]; // second position in string array. if((line = br.readline()) != null) { string[] splits = line.split("="); name = splits[1]; } } }
Comments
Post a Comment