How to read a text file using .NET Framework classes
Created On: 16 January 2012
How does one read a text file using the .NET Framework classes in Visual COBOL?
You should look at the System.IO namespace and classes like StreamReader and File in order to accomplish the task of reading a text file in a variety of different ways.
program-id. Program1 as "testreadtext.Program1".
01 sr type StreamReader.
01 wsLine string.
01 wsException type Exception.
*> 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
*> Let the user know what went wrong.
display "The file could not be read:"
01 #lines string occurs any.
set #lines to type System.IO.File::ReadAllLines("debug.txt")
Standard COBOL I-O still works fine.
open input textfile
Old KB# 35384