/tutorial/io/text_file_read_example.e
Specman e | 38 lines | 25 code | 3 blank | 10 comment | 1 complexity | 54f673be70bb9b5dc75cfcc0bb386ec1 MD5 | raw file
1class 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 13create {ANY} 14 make 15 16feature {} 17 make 18 local 19 text_file_read: TEXT_FILE_READ; path: STRING 20 do 21 path := "text_file_read_example.e" 22 create text_file_read.connect_to(path) 23 if text_file_read.is_connected then 24 from 25 text_file_read.read_character 26 until 27 text_file_read.end_of_input 28 loop 29 io.put_character(text_file_read.last_character) 30 text_file_read.read_character 31 end 32 text_file_read.disconnect 33 else 34 io.put_string("Cannot read file %"" + path + "%" in the current working directory.%N") 35 end 36 end 37 38end -- class TEXT_FILE_READ_EXAMPLE