Join Peggy Fisher for an in-depth discussion in this video Solution: Loading a file, part of Up and Running with Java.
- View Offline
- Exercise Files
- This latest challenge was designed…to give you practice with reading and writing files.…Let's take a look at my solution…and, as always, remember that your solution…might be very different.…Also, I do wanna point out if your program…seems to work but the output file is empty…every time, check to make sure you close the file…before exiting your program.…Okay, at the top of my program we have…our import statements.…We import jave.io.* to allow us to read…and write from files.…
In the main part of the program, the first thing…I did was to clear my input file,…File menuItems = new File…("menuNoPrices.txt").…I'll show you the file real quickly.…I'll go to Windows Explorer.…I'm already in my FileChallenge,…and here is my menuNoPrices.…If I open it up, you can see…I have eight different menu items.…Okay, let's go back to the program.…I'm also creating my file for the output.…This one's going to be called menuWithPrices.txt.…
That file doesn't exist yet,…but because it's an output file,…the program will go ahead and create it.…
- Downloading and exploring NetBeans
- Understanding Java basics: data types, strings, arrays, and more
- Controlling flow with functions and loops
- Creating classes
- Sorting and searching arrays
- Manipulating files
- Handling errors
- Building GUIs
Skill Level Beginner
1. Getting Started
2. Java Basics
3. Flow of Control
4. Classes and Objects
5. Beyond the Basics
6. File Manipulation
7. Graphical User Interface Basics
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.