//************************************** // Name: File Input/Output // Description:This program takes the input of one file and outputs it to another in plain text. There are NO compression schemes here to change the text to other formats, but if you save this file as a .gif and try to open it in Adobe Photoshop you will be out of luck. Simple yet complex, check it out. // By: Nick Campbell (from psc cd) // // // Inputs:Inputs from a file that you have to create!...YOU MUST CREATE A FILE WITH INTS in it on separate lines! // // Returns:....doesn't return anything just outputs to a file // //Assumes:None // //Side Effects:....haven't thought of anything unless you just don't make a file....SO MAKE A FILE WITH INTS in it on separate lines! //************************************** import java.io.*; import java.util.*; public class IO { /* * Programmer: Nick Campbell aka NC * Date: Last changed December 12, 2001 * * Note from Author - *This program helps to teach the novice about input and output from a file. The prereq's for * this program are: * - Reference Variables * - Some terminology ( parse, initialize, token, etc...) Nothing big * - Some knowledge of the java libraries * This isn't too complex you can make it so that the user is inputing and outputing the info to * the file...you just need to find the correct parsing information and work on the code a little * bit. Have fun and learn alot. * * Shouts to Dave, Ben, and Dr. Gann (my professor) at Hartwick College, in Oneonta NY... * Programming Technique used here learned at Hartwick the programmers own time */ public static void main(String[] args) throws IOException { // Test is initialized here to make use of the input read from a file, all integers.... int test = 0; // Reference Variables for input and output to and from files... BufferedReader inputStream = new BufferedReader(new FileReader("IO.txt")); PrintWriter outputStream = new PrintWriter(new FileWriter("IO.dat")); // Outputs 2 lines to the file to start the file.... outputStream.println("+---- Testing output to a file ----+"); outputStream.println(); // Initializes var so that the loop works String var = inputStream.readLine(); while(var != null) { // StringTokenizer is a class in java.util.* takes the string and parses it by specifications // good for phone books, address books, database reciepts etc... StringTokenizer st = new StringTokenizer(var); test = Integer.parseInt(st.nextToken()); outputStream.println(test); var = inputStream.readLine(); } inputStream.close(); outputStream.close(); } }