/tutorial/io/text_file_read_example.e

http://github.com/tybor/Liberty · Specman e · 38 lines · 25 code · 3 blank · 10 comment · 1 complexity · 54f673be70bb9b5dc75cfcc0bb386ec1 MD5 · raw file

  1. class TEXT_FILE_READ_EXAMPLE
  2. --
  3. -- This example reads a text file character by character and puts each character on the screen.
  4. --
  5. -- If you compile and run this class in the current working directory, you'll see this file !
  6. --
  7. -- In order to read a file, read a character and then use
  8. -- last_character ONLY if if end_of_input has not been reached
  9. -- while reading the character.
  10. --
  11. -- More informations in the FAQ.
  12. create {ANY}
  13. make
  14. feature {}
  15. make
  16. local
  17. text_file_read: TEXT_FILE_READ; path: STRING
  18. do
  19. path := "text_file_read_example.e"
  20. create text_file_read.connect_to(path)
  21. if text_file_read.is_connected then
  22. from
  23. text_file_read.read_character
  24. until
  25. text_file_read.end_of_input
  26. loop
  27. io.put_character(text_file_read.last_character)
  28. text_file_read.read_character
  29. end
  30. text_file_read.disconnect
  31. else
  32. io.put_string("Cannot read file %"" + path + "%" in the current working directory.%N")
  33. end
  34. end
  35. end -- class TEXT_FILE_READ_EXAMPLE