Java #47: How to Read From a Previously Created File in Java

//The text file says “Welcome to your new file!”

It’s easier to understand how to read from files with the whole program, so the Java source code is below.

——————————————–Beginning of program——————————

//Programmer:Akinwale Owi
//Company: Dagba Computers
//Program Purpose:How to Read From A Previously Created File in Java

package dagbacomputers;

//imports
import java.io.FileReader;

//Beginning of DagbaComputers (Class containing the Main function)
public class DagbaComputers
{

//Main Function
public static void main(String[] args) throws Exception
{
//Creating the FileReader
FileReader fileSurfer = new FileReader(“BrandNew.txt”);

//integer that will run through the file
int a;

//loop to print out contents of file
while((a = fileSurfer.read())!=-1)

//Printing out each char of the file
System.out.print((char)a);

//end of while

//Closing the File
fileSurfer.close();
}
//End of Main Function
}
//End of DagbaComputers Class

——————————————-End of Program————————————–

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: