bayne94 1 Report post Posted August 5, 2020 Hello all, This is a program I wrote in java to check the client files for for gem descriptions. import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class StringArraySearch { public static void main(String[] args) throws IOException{ //Creation of File Descriptor for input file File readFile = new File("src/stonehint.txt"); //Intialize the word Array String[] fileWords=null; //Creation of File Reader object FileReader fr = new FileReader(readFile); //Creation of BufferedReader object BufferedReader br = new BufferedReader(fr); String stringCheck; String[] input={ "ItemHint_LieYanS", "ItemHint_ZhiYanS", "ItemHint_HuoYaoS", "ItemHint_MaNaoS", "ItemHint_HanYu", "ItemHint_YueZhiX", "ItemHint_ShuiLingS", "ItemHint_ShengGuangS", "ItemHint_FengLingS", "ItemHint_YingYanS", "ItemHint_YanVitS", "ItemHint_YanStrS", "ItemHint_LongZhiTong", "ItemHint_LongZhiHun", "ItemHint_LongZhiXin", "ItemHint_GaNaZhiShen", "ItemHint_HuangYu", "ItemHint_ChiYu", "ItemHint_QingYu", "ItemHint_XTLingGuang", "ItemHint_LKBiZhong", "ItemHint_BBDuoShan", "ItemHint_FFDiYu", "ItemHint_XKQiangHua", "ItemHint_SShuiyao", "ItemHint_SSbusi", "ItemHint_SSguangmang", "ItemHint_SSningju", "ItemHint_SSxuanwu", "ItemHint_HLS", "ItemHint_HYS", "ItemHint_HJS", "ItemHint_BLS", "ItemHint_BYS", "ItemHint_BJS", "ItemHint_CLS", "ItemHint_CYS", "ItemHint_CJS", "ItemHint_ZLS", "ItemHint_ZYS", "ItemHint_ZJS", "ItemHint_QLS", "ItemHint_QYS", "ItemHint_QJS", "ItemHint_GGR", "ItemHint_GGS", "ItemHint_GGOS", "ItemHint_GGC", "ItemHint_GGW", "ItemHint_JinYanS", "ItemHint_MuYanS", "ItemHint_ShuiYanS", "ItemHint_HuoYanS", "ItemHint_TuYanS" }; //Variable to check increments int count=0; //Reading Content from the file while((stringCheck = br.readLine())!=null){ //Split the word using space fileWords = stringCheck.split(" "); for (String word : fileWords){ for (int i = 0; i < input.length; i++){ //Search for the given word if (word.equals(input[i])){ System.out.println(input[i] + " is present in the file"); count++; } } } } System.out.println(""); System.out.println("There are "+count+" gem descriptions in the file"); fr.close(); }//close main method }//class How useful is it? Not very lol. 1 Quote Share this post Link to post Share on other sites
champ 159 Report post Posted August 6, 2020 you should try reading from file rather than hardcoding user input, other than that - well done! Quote Share this post Link to post Share on other sites
Hydra 1 Report post Posted August 8, 2020 What exactly are you trying to do? Looks like a standard search for a keyword, you could possibly try using Regexp for a performance improvement if that's something you think needs improvement. Quote Share this post Link to post Share on other sites