Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.lib.shitTesting;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- class Help{
- String filename;
- Help(String fname){
- filename=fname;
- }
- boolean helpOn(String what) {
- int ch;
- String topic, info;
- try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
- do {
- ch = br.read();
- if(ch=='#'){
- topic=br.readLine();
- if(topic.compareTo(what)==0){
- do {
- info = br.readLine();
- if(info!=null)System.out.println(info);
- }while((info!=null) && (info.compareTo("")!=0));
- return true;
- }
- }
- } while (ch != -1);
- }
- catch(IOException exc){
- System.out.println("Ошибка ввода-вывода"+exc);
- return false;
- }
- return false;
- }
- String getSelection(){
- String topic="";
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- System.out.println("укажите тему");
- try{
- topic=br.readLine();
- }
- catch (IOException exc){
- System.out.println("Ошибка при вводе с консоли");
- }
- return topic;
- }
- }
- class FileHelp{
- public static void main(String args[])throws IOException{
- Help helpobj=new Help("TEXT");
- String topic;
- System.out.println("Вам предоставлена справка. Для остановки нажмите stop");
- do{
- topic=helpobj.getSelection();
- if(!helpobj.helpOn(topic)){
- System.out.println("Справка не найдена. Повторите!");
- }
- }while(topic.compareTo("stop")!=0);
- }
- }
Add Comment
Please, Sign In to add comment