- 01Setting up (what you'll need)
- 02Your first output (println)
- 03Using variables
- 04Branching (the if statement)
- 05Repeating (the for loop)
- 06Writing your own function
- 07Working with arrays
- 08Repeating (the while loop)
- 09Working with structs
- 10Error handling (try-catch)
- 11Sorting an array
- 12Recursive functions
- 13Using the handy built-in functions
- 14The basics of multiple dispatch
- 15The ternary operator
- 16Building a type hierarchy with abstract types
- 17Writing comments
- 18Logical operators (&&, ||, !)
- 19Constants (const)
- 20Splitting and joining strings (split and join)
- 21Writing nothing-safe code
- 22Searching an array (in)
- 23Transforming an array with map
- 24Two-dimensional arrays (tabular data)
- 25Creating your own exception type
- 26Default arguments
- 27Handling sets (data without duplicates) with Set
- 28Checking correctness (a first step towards testing)
- 29Higher-order functions (passing a function as an argument)
- 30Stacks and queues (the basics of data structures)
- 31The basics of type conversion (casting)
- 32An introduction to regular expressions (pattern matching)
- 33The binary search algorithm
- 34Building a Caesar cipher (a letter-shifting cipher)
- 35Understanding how bubble sort works
- 36Assembling and displaying a date
- 37Writing several tests together (multiple test cases)
- 38Speeding up calculation with memoization (caching)
- 39Normalizing strings (strip and case)
- 40Shallow copies versus deep copies
- 41The basics of enums
- 42Flattening an array
- 43Reversing a string and testing for a palindrome
- 44Pairing up two arrays (the zip operation)
- 45Rounding numbers (floor, ceil, round)
- 46Multi-line strings (triple quotes)
- 47Returning several values from a function
- 48Finding the GCD and LCM
- 49Formatting numbers (aligning digits and decimal places)
- 50Cleaning up with try / catch / finally
- 51Writing general functions with type parameters
- 52The basics of reading and writing files
- 53Generating random numbers
- 54Bitwise operations (AND, OR, XOR, shifts)
- 55Receiving command-line arguments
- 56Pausing for a set time (sleep)
- 57Watch out for floating-point error
- 58Reading a value from standard input
- 59FizzBuzz (the classic exercise)
- 60Testing whether a number is prime
- 61Set operations with Set (union, intersection, difference)
- 62Converting between bases (binary and hexadecimal)
- 63Checking that brackets match (an application of stacks)
- 64Testing whether two words are anagrams
- 65Testing whether a year is a leap year
- 66Converting temperatures (Celsius and Fahrenheit)
- 67Finding the prime factors
- 68[Project] Build a simple inventory system
The basics of reading and writing files
This lesson covers reading and writing files in Julia, with the aim of saving and loading text from a program.
Combining open() with a do block gives you a safe form that opens a file, does the work, and closes it automatically. Saving configuration and logs makes this a basic everyday operation.
The sample code opens a file with open("memo.txt", "w") do f ... end and saves the contents with write(f, ...). Note that the file is closed automatically on leaving the do block.
A common early stumble is the do block itself. It is really syntax for passing an anonymous function, which is confusing if you have not met callbacks before.
In professional work, that do block is valued as a safe resource-management mechanism that heads off the bug of forgetting to close a file.
๐งช This site can't compile or run Julia directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
