Input -- Output 3/3/2010, 3:03 PM = 1.5 Input and Output ? Goal: java programs that interact with the outside world ? Input devices: keyboard, mouse, hard drive, network, digital camera, microphone ? Output devices: display, speakers, hard drive, network, printer, mp3 player ? Our approach ? Define java libraries of functions for input and output ? Use operating system (OS) to connect java programs to: file system, each other, keyboard, mouse, display, speakers ? Terminal: application where you can type commands to control the operating system ? Command-Line Input and Standard Output ? Command-line input: read an integer N as command-line argument ? Standard output ? Flexible OS abstraction for output ? In java, output from System.out.println() goes to standard output ? By default, standard output is sent to Terminal ? Command-line inputs ? Use command-line inputs to read in a few user values ? Not practical for many user inputs ? Input entered before program begins execution ? Standard input ? Flexible OS abstraction for input ? By default, standard input is received from Terminal window ? Input entered while program is running ? To use: download StdIn.java and StdOut.java from booksite, and put in working directory (or use classpath) ? Redirecting standard output ? Use OS directive to send standard output to a file for permanent storage (instead of terminal window) ? Java RandomSeq 1000 data.txt (must be a new file name for each file---overwrites any current data in that file) ? Can also take information from a particular file ? more data.txt ? Takes the contents of a single screen full of a file and displays it on the screen ? java Average data.txt ? PIPING: Java RandomSeq 1000000 | java Average ? Takes all the data from the random seq program and takes the average of that data ? Returns only the average of the data ? Can use as many pipes as you want-- can go from program to program to program to program ? Standard Draw ? We provide library StdDraw to plot graphics ? Download StdDraw.java and put in working directory
Want to see the other 1 page(s) in Input -- Output?JOIN TODAY FOR FREE!