
-----------------------------------
mendem03
Fri Jun 04, 2010 9:32 am

reading and writing to text file
-----------------------------------
 
import java.io.*;
class finalproject_InterestRate
{
		public static void main(String

Need help for reading and writing this program to a text file.
Can someone please help me.

-----------------------------------
Unnamed.t
Fri Jun 04, 2010 5:38 pm

Re: reading and writing to text file
-----------------------------------
INPUT:: You are currently using a DataInput object in coordination with a System.in input stream.
OUTPUT:: You are currently using System.out

What you need to do is one of the following:

INPUT

Use the scanning method from java.util.Scanner class

Scanner in= new Scanner (new File ("Filename.txt"));

Check the different types of inputs that can be performed by using Help Reference of the Java class libraries (can be found on the sun microsystems java site)

OR

Use the BufferedReader method from java.io.BufferedReader class

BufferedReader in = new BufferedReader (new FileReader ("Filename.txt"));

Check the different types of inputs that can be performed by using Help Reference of the Java class libraries (can be found on the sun microsystems java site)

OUTPUT

Use the PrintWriter method from java.io.PrintWriter class

PrintWriter out = new PrintWriter (new FileWriter ("Filename.txt"));

This can be used to output text to your file. Once again check java class libraries for methods e.g. out.println ();/out.print (); 

OR

Use the BufferedWriter method from java.io.BufferedWriter class

BufferedWriter out = new BufferedWriter (new FileWriter ("Filename.txt"));

Check the different types of inputs that can be performed by using Help Reference of the Java class libraries (can be found on the sun microsystems java site)

Website for class libraries: http://java.sun.com/j2se/1.5.0/docs/api/
