public class ListMaker extends Main { static ArrayList tempList2; private static Playerloc p; public static List readDataFromFile() { List listofusers = new ArrayList(); FileInputStream fstream = null; try { fstream = new FileInputStream("src/list.txt"); BufferedReader br = new BufferedReader(new InputStreamReader( fstream)); String strLine = ""; String[] tokens = strLine.split(", "); // Read file line by line while ((strLine = br.readLine()) != null) { // Copy the content into the array tokens = strLine.split(", "); listofusers.add(new Playerloc(tokens[0], tokens[1], tokens[2], tokens[3])); } } catch (IOException e) { e.printStackTrace(); } finally { try { fstream.close(); tempList2 = (ArrayList) listofusers; } catch (Exception ignore) { } } return listofusers; } public void insertPlayerlocRow(String name, String x, String y, String z) { List list = readDataFromFile(); Playerloc pLoc = new Playerloc(name, x, y, z); // Add row to ArrayList list.add(pLoc); // Update file updateFile("src/list.txt", list); } public static void updateFile(String filename, List userDataList) { BufferedWriter bufferedWriter = null; try { bufferedWriter = new BufferedWriter(new FileWriter(filename)); } catch (IOException ex) { ex.printStackTrace(); } Playerloc pLoc; String row; for (int i = 0; i < userDataList.size(); i++) { pLoc = userDataList.get(i); row = pLoc.name + ", " + pLoc.Xx + ", " + pLoc.Yy + ", " + pLoc.Zz + "/n"; try { bufferedWriter.write(row); bufferedWriter.newLine(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } // Close the BufferedWriter try { if (bufferedWriter != null) { bufferedWriter.flush(); bufferedWriter.close(); } } catch (IOException ex) { ex.printStackTrace(); } } public static void print() { if (tempList2.contains(p)) { tempList = tempList2; } } }