File Functions

These functions are used to read and write text files in SRON. Make note that SRON doesn't provides the functionality to work on binary files, you can only read/write text files only.

SRON provides 14 functions for this:

  • freader()

  • fwriter()

  • fclose()

  • fisOpen

  • fisEnd

  • fgetName()

  • freset()

  • fcurPos()

  • fsetSeek()

  • freadChar()

  • freadLine()

  • freadWhole()

  • fwriteChar()

  • fwriteString()


1. freader():

  • This function is used to read the text file.

  • It returns a 'FileReader' object.

OUTPUT :

Files Loaded!


2. fwriter():

  • This function is used to create a writeable text file.

  • If the mentioned file doesn't exists, then it creates one.

  • If the file already exists, then it clears the content of the file and writes the fresh new content.

  • If you want to retain the current content of the file, then pass 'true' as the second argument which tells the function to open the file in append mode.

OUTPUT :

Files loaded!


3. fclose():

  • This function is used to close a file.

  • Even if you forget to call it, SRON's Garbage collector does it for you so you don't have to worry.

OUTPUT :

Files loaded and closed!


4. fisOpen:

  • This function is check if the file is loaded succesfully or not.

  • Returns true if file is loaded/created otherwise false.

OUTPUT :

File doesn't exists!


5. fisEnd:

  • This function is used to check if you have reached the end while reading the file.

  • If you have reached the end, it will return true otherwise false.

  • It can only be used for FileReader object.

OUTPUT :

Hello, SRON! Today is June 27, 2003.


6. fgetName():

  • This function is used to know the name of the file you are reading/writing.

  • Returns a 'String' containing file name.

  • If the file is closed or failed to load, then it returns an empty string.

  • Can be used to know the name of both FileReader and FileWriter files.

OUTPUT :

file.txt After closing, file name = ''


7. freset():

This function is used to reset the file by putting the seek to the start of the file.

OUTPUT :

First line Second line First line


8. fcurPos():

  • This function is used to check at what position is your seek at.

  • Returns an 'Int' value syndicating the index.

OUTPUT :

Current Position= 0 Current Position= 5


9. fsetSeek():

This function is used to set the seek's position on the file.

OUTPUT :

2 10


10. freadChar():

  • This function is used to read a single character from file.

  • It returns '\0'(Ascii 0) if the file is

    • closed,

    • failed to load

    • or reached the end.

  • After reading the single character, the seek is incremented one position.

OUTPUT :

S R


11. freadLine():

  • This function is used to read a line from the file.

  • If file's seek is reached at the end, then it returns an empty string.

OUTPUT :

Hello, there Welcome to Saksham Rapid Object Notation


12. freadWhole():

This function is used to read all the content of the file after the current seek position.

OUTPUT :

Hello, there!! Welcome to Saksham Rapid Object Notation. You must be enjoying learning SRON. All the best for your great journey.


13. fwriteChar():

  • This function is used to write a single character to a file.

OUTPUT :

// file.txt S


14. fwriteString():

  • This function is used to write a string to a file.

OUTPUT :

// file.txt 27062003


Last updated