Master_Tiroman

Справка с чтением

Oct 7th, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. package com.example.lib.shitTesting;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7.  
  8. class Help{
  9. String filename;
  10.  
  11. Help(String fname){
  12. filename=fname;
  13. }
  14.  
  15. boolean helpOn(String what) {
  16. int ch;
  17. String topic, info;
  18.  
  19. try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
  20. do {
  21. ch = br.read();
  22. if(ch=='#'){
  23. topic=br.readLine();
  24. if(topic.compareTo(what)==0){
  25. do {
  26. info = br.readLine();
  27. if(info!=null)System.out.println(info);
  28. }while((info!=null) && (info.compareTo("")!=0));
  29. return true;
  30. }
  31. }
  32. } while (ch != -1);
  33. }
  34. catch(IOException exc){
  35. System.out.println("Ошибка ввода-вывода"+exc);
  36. return false;
  37. }
  38. return false;
  39. }
  40.  
  41. String getSelection(){
  42. String topic="";
  43.  
  44. BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  45. System.out.println("укажите тему");
  46. try{
  47. topic=br.readLine();
  48. }
  49. catch (IOException exc){
  50. System.out.println("Ошибка при вводе с консоли");
  51. }
  52. return topic;
  53. }
  54. }
  55.  
  56. class FileHelp{
  57. public static void main(String args[])throws IOException{
  58. Help helpobj=new Help("TEXT");
  59. String topic;
  60.  
  61. System.out.println("Вам предоставлена справка. Для остановки нажмите stop");
  62. do{
  63. topic=helpobj.getSelection();
  64.  
  65. if(!helpobj.helpOn(topic)){
  66. System.out.println("Справка не найдена. Повторите!");
  67. }
  68. }while(topic.compareTo("stop")!=0);
  69.  
  70. }
  71. }
Add Comment
Please, Sign In to add comment