VB icon

File Input/Output

Email
Submitted on: 1/2/2015 5:59:00 PM
By: Nick Campbell (from psc cd)  
Level: Beginner
User Rating: By 4 Users
Compatibility: Java (JDK 1.1), Java (JDK 1.2)
Views: 1900
 
     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.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// 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
//
// 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();
	}
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.