Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. package com.javarush.task.task18.task1828;
  2.  
  3. /*
  4. Прайсы 2
  5. */
  6.  
  7. import java.io.*;
  8. import java.util.ArrayList;
  9.  
  10. public class Solution
  11. {
  12. public static void main(String[] args) throws IOException
  13. {
  14. String id;
  15. String productName = null;
  16. String price = null;
  17. String quantity = null;
  18. String tmp;
  19. boolean replase = false;
  20. if ("-d".equals (args[0]))
  21. {
  22. id = args[1];
  23. }
  24. else if ("-u".equals (args[0]))
  25. {
  26. id = args[1];
  27. productName = args[2];
  28. price = args[3];
  29. quantity = args[4];
  30. replase = true;
  31. }
  32. else
  33. {
  34. return;
  35. }
  36. BufferedReader reader = new BufferedReader (new InputStreamReader (System.in));
  37. String fileName;
  38. fileName = reader.readLine ( );
  39. // fileName = "c:/1";
  40. BufferedReader readerF = new BufferedReader (new FileReader (fileName));
  41. ArrayList<String> list = new ArrayList<> ( );
  42. while (readerF.ready ( ))
  43. {
  44. list.add (readerF.readLine ( ));
  45. }
  46. BufferedWriter writerF = new BufferedWriter (new FileWriter (fileName));
  47. for (int i = 0; i < list.size ( ); i++)
  48. {
  49. String s = list.get (i);
  50. int k = s.indexOf (" ");
  51. if (k > 8)
  52. tmp = s.substring (0, 8);
  53.  
  54. else
  55. tmp = s.substring (0, k);
  56. if (Long.parseLong (tmp) != Long.parseLong (id))
  57. {
  58. writerF.write (s);
  59. if (i != (list.size ( ) - 1))
  60. writerF.write ("\n");
  61. }
  62. else
  63. {
  64. if (replase)
  65. { tmp = String.format ("%-8s%-30.30s%-8s%-4s", id, productName, price, quantity);
  66. writerF.write (tmp.toString ( ));
  67. if (i != (list.size ( ) - 1))
  68. writerF.write ("\n");
  69. }
  70. }
  71. }
  72. reader.close ( );
  73. readerF.close ( );
  74. writerF.close ( );
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement