NOTICE: Our Community is moving. Get more information.
$set ilusing"System.IO" program-id. Program1 as "testreadtext.Program1". data division. working-storage section. 01 sr type StreamReader. 01 wsLine string. 01 wsException type Exception. procedure division. try *> Create an instance of StreamReader to read from a file. set sr to new type StreamReader("testfile.txt") *> Read and display lines from the file until the end of *> the file is reached. perform until exit set wsLine to sr::ReadLine if wsLine = null exit perform *>EOF reached else display wsLine end-if end-perform catch wsException *> Let the user know what went wrong. display "The file could not be read:" display wsException::Message end-try invoke sr::Close goback.
Example #2:01 #lines string occurs any. set #lines to type System.IO.File::ReadAllLines("debug.txt")Example #3:Standard COBOL I-O still works fine.open input textfileread textfile at end display "done"end-read