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

How to use Filesystem API


I want to make an application that creates a file named "config.txt" and read/write to it but i am hanging on creating the file. Can't find how to create the file.



My Project: Github_Project_Line85

I want to save the IP that the user writes in and after rebooting it should stay. (Line 85)

I want to make a check system with the config.txt and then load the variable into it.

It's using the GUI API from MineOS


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

It writes to the current line of a new file, so in this case it'd be the 1st line. To read the first line just open the file in read mode `

file = io.open("myfile", "r")

Ip = file:read("*l")



*l reads 1 line from a file 1 reads one byte from a file

Link to post
Share on other sites
  • 0

Firstly you're mixing up file:read and file:write.. One writes to the file and the other reads.

local config = {}
for line in io.lines "/path/to/config.txt" do
  table.insert(config, line)

print(config[3]) -- # 3rd line in your config
-- # this is probably the simplest way but there are others.

To read a specific line in a file you'd have to know the exact offset of bytes until the information you're trying to read.

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.

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.


  • Create New...

Important Information

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