Here's a small snippet I use for reading accounts from a file, you should be able to take from it what you need.
private void readAccounts() {
// The name of the file to open.
String fileName = "accounts.txt";
// This will reference one line at a time
String line = null;
try {
// FileReader reads text files in the default encoding.
FileReader fileReader =
new FileReader(getDirectoryData() + fileName);
// Always wrap FileReader in BufferedReader.
BufferedReader bufferedReader =
new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null) {
String[] lineInfo = line.split(":");
vars.addToAccounts(lineInfo);
}
// Always close files.
bufferedReader.close();
vars.setCheckedFile(true);
}
catch(FileNotFoundException ex) {
log("Accounts file not found, stopping script");
stop(false);
}
catch(IOException ex) {
log("Error reading file, stopping script");
stop(false);
}
}
Probably not the best way to do this but works none the less.