Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Ta©ti Tac0Z

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

Question

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 :)

Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0
  • Solution

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. 

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

 

 

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 '..' .

I.e. 

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

file:write(s)

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)

Link to post
Share on other sites
  • 0

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

e.g.

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

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.