Chapter 8
Working with Files

All the programs you’ve worked with so far have taken input from the end user or used hard-coded values. But many programs use files to store data. Your operating system and its programs write logs to files constantly, as do the websites you visit. And many apps use files to hold configuration data. Games use files to store your saved data when you reach a checkpoint.

Even programming languages, like the one you’re using to work through this book, work with files. You type your source code into a file, and a compiler or interpreter turns what you wrote into something the computer can run.

The exercises in this chapter ask you to work with files and folders, and you’ll need to investigate how to do this in your programming language. Some languages have built-in features to read from a file. Others don’t have the features built in but do have libraries you can use to work with files.

You’ll want to investigate different approaches, too. You might find that your program performs faster if you can process the file line by line or as a stream of data. Some files are just too big to load all at once, but some situations may require you to read the whole file first before you can process it.

One quick note: if you’re using JavaScript inside the web browser, you won’t be able to do these exercises without modification because browsers prevent you from reading and writing to the local file system. You can use Node.js instead.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.93.210