How to Run a Disk-Oriented Program in Java - dummies

By Barry Burd

To deal with volumes of data in Java, you need tools for reading from (and writing to) disk files. At the mere mention of disk files, some peoples’ hearts start to palpitate with fear. After all, a disk file is elusive and invisible. It’s stored somewhere inside your computer, with some magic magnetic process.

The truth is, getting data from a disk is very much like getting data from the keyboard. And printing data to a disk is like printing data to the computer screen.

For your purposes here, displaying a program’s text output “on the computer screen” means displaying text in Eclipse’s Console view. If you shun Eclipse in favor of a different IDE (such as NetBeans or IntelliJ IDEA) or you shun all IDEs in favor of your system’s command window, then, for you, “on the computer screen” means something slightly different. Please read between the lines as necessary.

Also, some computers have flash memory with no honest-to-goodness disks inside them. So terms like “disk-oriented” and “disk files” are showing signs of age. But let’s face facts: A “record store” no longer sells vinyl records. Today’s LCD screens no longer need saving. And, a web page’s radio buttons don’t mark your favorite stations.

Consider the scenario when you run some code. You type some stuff on the keyboard. The program takes this stuff and spits out some stuff of its own. The program sends this new stuff to the Console view. In effect, the flow of data goes from the keyboard, to the computer’s innards, and on to the screen.

The flow of data when you run code on a disk-oriented program in java.

There’s a file containing data on your hard drive. The program takes data from the disk file and spits out some brand-new data. The program then sends the new data to another file on the hard drive. In effect, the flow of data goes from a disk file, to the computer’s innards, and on to another disk file.

A program processes raw data and sends out cooked data onto another file.

These two scenarios are very similar. In fact, it helps to remember these fundamental points:

  • The stuff in a disk file is no different from the stuff that you type on a keyboard.

    If a keyboard-reading program expects you to type 19.95 5, then the corresponding disk-reading program expects a file containing those same characters, 19.95 5. If a keyboard-reading program expects you to press Enter and type more characters, then the corresponding disk-reading program expects more characters on the next line in the file.

  • The stuff in a disk file is no different from the stuff that you see in Eclipse’s Console view.

    If a screen-printing program displays the number 99.75, then the corresponding disk-writing program writes the number 99.75 to a file. If a screen-printing program moves the cursor to the next line, then the corresponding disk-writing program creates a new line in the file.

If you have trouble imagining what you have in a disk file, just imagine the text that you would type on the keyboard or the text that you would see on the computer screen (that is, in Eclipse’s Console view). That same text can appear in a file on your disk.