tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
43
Task/Read-entire-file/NetRexx/read-entire-file.netrexx
Normal file
43
Task/Read-entire-file/NetRexx/read-entire-file.netrexx
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
parse arg inFileName .
|
||||
|
||||
if inFileName = '' | inFileName = '.' then inFileName = './data/dwarfs.json'
|
||||
fileContents = slurp(inFileName)
|
||||
say fileContents
|
||||
|
||||
return
|
||||
|
||||
-- Slurp a file and return contents as a Rexx string
|
||||
method slurp(inFileName) public static returns Rexx
|
||||
|
||||
slurped = Rexx null
|
||||
slurpStr = StringBuilder()
|
||||
ioBuffer = byte[1024]
|
||||
inBytes = int 0
|
||||
|
||||
do
|
||||
inFile = File(inFileName)
|
||||
inFileIS = BufferedInputStream(FileInputStream(inFile))
|
||||
|
||||
loop label ioLoop until inBytes = -1
|
||||
slurpStr.append(String(ioBuffer, 0, inBytes))
|
||||
inBytes = inFileIS.read(ioBuffer)
|
||||
end ioLoop
|
||||
|
||||
catch exFNF = FileNotFoundException
|
||||
exFNF.printStackTrace
|
||||
catch exIO = IOException
|
||||
exIO.printStackTrace
|
||||
finally
|
||||
do
|
||||
inFileIS.close()
|
||||
catch ex = IOException
|
||||
ex.printStackTrace
|
||||
end
|
||||
end
|
||||
|
||||
slurped = Rexx(slurpStr.toString)
|
||||
|
||||
return slurped
|
||||
Loading…
Add table
Add a link
Reference in a new issue