Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • Announcements

    • Lizzy Trickster

      Latest Stable OpenComputers Version   11/26/16

      The latest released version of OpenComputers is version 1.7 for MC 1.7.10, 1.8.9, 1.9.4, 1.10.2, 1.11.2 & 1.12.1. See more information here! Beta/Dev builds can be found at the Jenkins Build Server (ci.cil.li)
  • 0

io.open() or/and filesystem.open()???


hallo here i am again... i know dum question again!

1. what to use filesystem.open or io.open i know that it is the same but what is the best one


2. and how to pick a new line weren in write mode (what i mean is that how can i like write a thing on line 1 and then on line number 10 or 2 or whatever like in

terminal like term.setCursor can i do that in io.open two in write mode)


what i wil say is how to write new line or how to do newline

i  also need to point out that i know there is i seek function but 1 i don't  no how to use it and 2 as i can understand do seek only work in read mode 



i have played opencomputers in a long time and i still don't understand io.open and filesystem.open fully



and yes i do know to the wiki and i do reading it some times so plese don't say that................. or write it :)

Share this post

Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0

1. According to the wiki 

  • Important*: it is generally recommended to use io.open instead of this function, to get a buffered wrapper for the file stream.

When opening files directly via the file system API you will get a file stream, a table with four functions. These functions are thin wrappers to the file system proxy's callbacks, which also means that read/write operations are not buffered, and can therefore be slow when reading few bytes often. You'll usually want to use io.open instead.

So yeah use io.

2. Text files are basically large strings of characters with a special newline character to indicate the text editor to display the rest of the string below the previous. Using the "\n" character you go down to the next line. So if you wanted to write to the 10th line you would need 9 \n's. Files don't work like the screen so you can't just set your cursor anywhere, instead you got to use a combination of spaces and newlines to get to that point. 

Share this post

Link to post
Share on other sites
  • 0

Ok thanks but so i need to write

"/n" in that string like so

data = io.open("/testfile", "w")

data: write("here is Line 1 /n here is line 2 /n here is Line 3 /n")

and then output: path /testfile:

here is Line 1

hare is Line 2

hare is Line 3


or is there a api for that or do i need to use the seek function fore that?



and ps: i no that i just can't set the cursor



Share this post

Link to post
Share on other sites
  • 0

From what I understand file:seek is only a method available when reading files with io.open. The char you need it backslash n or '\n'.

You can use the concatenation operator to join 2 strings into one. Looks like this '..' .


s = 'line 1\n' .. 'line 2\n' .. 'More lines...'


Share this post

Link to post
Share on other sites
  • 0

omg it is working thank you to you boft og your to help me came home after work and it is working.  


how the hell can i no that \n means newline unless two nice guys is telling me :)


i have trying to find out how to do that is so long time but NOW THERE IS A NEW BAT qest:


how can i write \ becuse i don't how to do it (i copy pastet it to write it here and in my owne computer in game)

Share this post

Link to post
Share on other sites
  • 0

Also, io.open takes RELATIVE or ABSOLUTE paths, ALL FILESYSTEM API methods ASSUME absolute paths


require("filesystem").open("file.txt") opens /file.txt

not /your/current/path/file.txt

compare to

io.open("file.txt") opens /your/current/path/file.txt


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now