TheScrub Posted August 20, 2013 Posted August 20, 2013 Accredit me if you use it please i release these out of my own time! this will return the data type of an ArrayList<String> from the text file we could do this for an int or pretty much any other type of object public ArrayList<String> readConfigSettings(String Path, int LineLimt) throws Throwable { BufferedReader br = new BufferedReader(new FileReader(new File(Path))); ArrayList<String> lines = new ArrayList<String>(); for (int i = 0; i < LineLimt; i++) { lines.add(i, br.readLine().toString()); } br.close(); return lines; } in use... using the file we produced using my other snippet on writing script settings.. ArrayList<String> settings = readConfigSettings((System.getProperty("user.home")+ File.separator + "OSBot" + File.separator + "data"+ File.separator + "settings.txt"),3); String option_one = settings.get(0); // the array starts at 0 String option_two = settings.get(1); int option_three = Integer.parseInt(settings.get(2));
Dreamliner Posted August 28, 2013 Posted August 28, 2013 You should replace for (int i = 0; i < LineLimt; i++) { lines.add(i, br.readLine().toString()); } with String line = null; int i = 0; while ((line = br.readLine()) != null) { lines.add(i++,line); } This eliminates having to know how long the file is!
TheScrub Posted August 29, 2013 Author Posted August 29, 2013 You should replace for (int i = 0; i < LineLimt; i++) { lines.add(i, br.readLine().toString()); } with String line = null; int i = 0; while ((line = br.readLine()) != null) { lines.add(i++,line); } This eliminates having to know how long the file is! yer i have that on mine didn't update not many people post on my snippets will update in 2 mins