Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String filepath = "data.txt";
- String newID = textFId.getText()
- String newRoadName = textFRname.getText();
- String newRoadNumber = textFRnumber.getText();
- String newCarType = textFCartype.getText();
- String tempFile = "datatemp.txt";
- File oldFile = new File(filepath);
- File newFile = new File(tempFile);
- String ID = "";
- String RoadName = "";
- String RoadNumber = "";
- String CarType = "";
- try {
- FileWriter fw = new FileWriter(tempFile, true);
- BufferedWriter bw = new BufferedWriter(fw);
- PrintWriter pw = new PrintWriter(bw);
- x = new Scanner(new File(filepath));
- x.useDelimiter("[,n]");
- while(x.hasNext()) {
- ID = x.next();
- RoadName = x.next();
- RoadNumber = x.next();
- CarType = x.next();
- if(ID.equals(newID)) {
- System.out.println(newID);
- pw.println(newID + "," + newRoadName + "," + newRoadNumber + "," + newCarType);
- } else {
- pw.println(ID + "," + RoadName + "," + RoadNumber + "," + CarType);
- System.out.println(newID);
- }
- }
- x.close();
- pw.flush();
- pw.close();
- oldFile.delete();
- File dump = new File(filepath);
- newFile.renameTo(dump);
- }
- catch (Exception e3){
- System.out.println("UPDATE ERROR!!");
- }
- 1,PO,100,GB
- 2,PO,101,GB
- 3,PO,102,GB
- 4,PO,103,GB
- 1,PO,100,GB
- 2,PO,101,GB
- 3,PO,102,GB
- 4,PO,104,GB
- 4,PO,104,GB
- 4,PO,104,GB
- 4,PO,104,GB
- 4,PO,104,GB
Add Comment
Please, Sign In to add comment