Guest User

Untitled

a guest
Jun 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. String filepath = "data.txt";
  2. String newID = textFId.getText()
  3. String newRoadName = textFRname.getText();
  4. String newRoadNumber = textFRnumber.getText();
  5. String newCarType = textFCartype.getText();
  6.  
  7. String tempFile = "datatemp.txt";
  8. File oldFile = new File(filepath);
  9. File newFile = new File(tempFile);
  10. String ID = "";
  11. String RoadName = "";
  12. String RoadNumber = "";
  13. String CarType = "";
  14.  
  15. try {
  16.  
  17. FileWriter fw = new FileWriter(tempFile, true);
  18. BufferedWriter bw = new BufferedWriter(fw);
  19. PrintWriter pw = new PrintWriter(bw);
  20. x = new Scanner(new File(filepath));
  21. x.useDelimiter("[,n]");
  22. while(x.hasNext()) {
  23. ID = x.next();
  24. RoadName = x.next();
  25. RoadNumber = x.next();
  26. CarType = x.next();
  27. if(ID.equals(newID)) {
  28. System.out.println(newID);
  29. pw.println(newID + "," + newRoadName + "," + newRoadNumber + "," + newCarType);
  30. } else {
  31. pw.println(ID + "," + RoadName + "," + RoadNumber + "," + CarType);
  32. System.out.println(newID);
  33. }
  34.  
  35. }
  36. x.close();
  37. pw.flush();
  38. pw.close();
  39. oldFile.delete();
  40. File dump = new File(filepath);
  41. newFile.renameTo(dump);
  42. }
  43. catch (Exception e3){
  44. System.out.println("UPDATE ERROR!!");
  45. }
  46.  
  47. 1,PO,100,GB
  48. 2,PO,101,GB
  49. 3,PO,102,GB
  50. 4,PO,103,GB
  51.  
  52. 1,PO,100,GB
  53. 2,PO,101,GB
  54. 3,PO,102,GB
  55. 4,PO,104,GB
  56.  
  57. 4,PO,104,GB
  58. 4,PO,104,GB
  59. 4,PO,104,GB
  60. 4,PO,104,GB
Add Comment
Please, Sign In to add comment