So I currently store a bunch of string titles together into a file on the user's phone and then read it later (when they relaunch the app). I'm trying to read back the string and split it on the delimiter I set for it but for some reason it splits it and then doubles the string...
So for example if I stored these strings
Ricky(har)Bobby(har)is(har)cool(har)
(har) is the delimiter I use to store them. (for example)
For some reason, when I use the split function on "har"
It gives me an array of strings, but doubles how many I stored... So the array of strings would have two Ricky's two Bobby's two is's and two cool's. I'm at a loss for what's going on to be honest. Been staring at this for hours... anyone have any idea?
line = BR.readLine();
String[] each = line.split("<TAG>");
for (int i = 0; i < each.length; i++) {
listOfCourses.add((each[i]));
//Toast.makeText(context, each[i], Toast.LENGTH_SHORT).show();
}
Here's the function that stores the data to the user's phone
//adds data into the classes file on user's phone
public void addClassesIntoFile(Context context, ArrayList<String> classList) {
try {
FileOutputStream fos = context.openFileOutput(CLASSLIST_FILENAME,
Context.MODE_PRIVATE | Context.MODE_APPEND);
OutputStreamWriter osw = new OutputStreamWriter(fos);
for (int i = 0; i < classList.size(); i++) {
osw.write(classList.get(i) + "<TAG>");
}
osw.flush();
osw.close();
} catch (FileNotFoundException e) {
// catch errors opening file
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}