4

I'm looking to read in a simple text file using the IO language and print it to the screen, so far I have:

f := File with("test.txt")
f openForReading

but just have no idea how to print it or clone the contents to an object. If anyone knows anything or could point me in a good direction it would be much appreciated.

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
user3047190
  • 319
  • 2
  • 7
  • Have you checked the [docs](http://iolanguage.org/scm/io/docs/reference/index.html#/Core/Core/File)? `asBuffer` and `readLine[s]` looks just like what you want. – Bergi Nov 28 '13 at 21:24

4 Answers4

2

Turns out it's very simple, just f contents. For any future reference to check for already existing methods for an object in io you can use protos, e.g. f protos

user3047190
  • 319
  • 2
  • 7
1

From the io> interactive shell, have you tried?

f print

or

doString(f)

See this blog

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
  • Yeah i got it eventually, turns out it's simply f contents. For future reference in case anyone reads this to get pre-set methods of an object simply type "File protos" or "[Object] protos" worked for me. – user3047190 Nov 28 '13 at 23:43
  • f contents. I did see this in some of the code samples, but I didn't understand its meaning. Please post your solution as your own answer and accept it. You're the one who found it. You're the one who should be credited for it. – Stephan Branczyk Nov 29 '13 at 00:16
1

Use readLine to read one line to a string, and println to print.

f := File with(fileName)
f openForReading

l := f readLine
l println
1

Create a File object with your specified path:

fileName := "yourFileName.txt"
file := File with(fileName)

Open and read the file into a variable

file open
fileText := file readToEnd

Then close the file.

file close 

You should then have the 'fileText' variable available for use.