Advertisement
Guest User

Untitled

a guest
May 30th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. public static void search() throws FileNotFoundException, IOException{
  2. BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
  3.  
  4.  
  5. FileReader info=new FileReader("inventory.txt");
  6. BufferedReader file = new BufferedReader(info);
  7.  
  8. String code, name, line, fileToSearch,opt,qty;
  9. System.out.println("♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦");
  10. System.out.println("→\t A. Search an item");
  11. System.out.println("♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦");
  12. System.out.println("→\t B. Display all");
  13. System.out.println("♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦");
  14. System.out.println("→\t Select Option[A/B]: ");
  15. opt=in.readLine();
  16.  
  17. switch (opt){
  18. case "A":
  19. case "a":
  20. System.out.println("Input item code: ");
  21. fileToSearch=in.readLine();
  22.  
  23. while((code=file.readLine())!= null){
  24. int indexFound=code.indexOf(fileToSearch);
  25.  
  26. if(indexFound>-1){
  27. System.out.println("Equipment is existing✔");
  28. System.out.println("");
  29. System.out.println("ITEM CODE\t\tITEM NAME\t\t\tQUANTITY: ");
  30. line=code;
  31. System.out.println(line);
  32. }
  33.  
  34.  
  35. }
  36. break;
  37.  
  38. case "B":
  39. case "b":
  40. //String line2;
  41. BufferedReader file2;
  42. //File inventory = new File("C:\Users\jaycee\Desktop\data\ENGINEERING-LABORATORY-INVENTORTY-APP\\inventory.txt");
  43. //if(!inventory.exists()){
  44. // inventory.createNewFile();
  45. //}
  46. file2=new BufferedReader(new FileReader("C:\\Users\\jaycee\\Desktop\\data\\ENGINEERING-LABORATORY-INVENTORTY-APP\\\\inventory.txt"));
  47. while((line=file2.readLine())!= null){
  48. System.out.println(line);
  49. }
  50. file2.close();
  51. break;
  52.  
  53. default:
  54. System.out.println("Invalid input");
  55. break;
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement