Jump to content

Reading Script Settings/Presets


TheScrub

Recommended Posts

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));
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...