Text file writing Flashcards

1
Q

what is a text file

A

A type of file that contains plain text and is often used for storing data that can be easily read and modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are the steps to create and write a text file

A
  1. declare a text file variable. This variable will be used to identify and manage the file you want to create or modify
  2. use theAssignFilefunction to assign a filename and location to your file. TheAssignFilefunction takes two arguments: the text file variable and the filename, as seen below
  3. open the file for writing using theRewritefunction. This function will create a new file if it doesn’t already exist or overwrite the file if it does exist. Here is how you can use theRewritefunction:
  4. start writing data to your text file using theWriteLnfunction. This function writes a line of text to the file and moves the cursor to the next line. Here’s an example:
  5. close the file using theCloseFilefunction. This function ensures that any changes you make to the file are saved and that the file is properly closed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how do we add new data to an existing file.

A
  1. first need to declare a text file variable that will represent the file you want to work with. You can do this by declaring a variable of type text
  2. Next, you need to associate your file variable with the file we want to add data to. We can do this using theAssignFilefunction, which takes two parameters:the file variable you want to associate with the file and the name of the file we want to work with
  3. Now that you have associated your file variable with the file you want to work with, you can open the file in append mode using theAppendfunction. This function takes one parameter:the file variable you want to open in append mode.
  4. When you open a file in append mode, any data we write to the file will be added to the end of the existing data, rather than overwriting it.
  5. Once the file is open in append mode, you can use theWriteLnfunction to write new data to the end of the file.
  6. When you are finished adding data to the file, you can use theClosefilefunction to close the file and ensure that our changes are saved
How well did you know this?
1
Not at all
2
3
4
5
Perfectly