Professor Kit Romano's Web Site

 



Site Index

About Me

Welcome
Definition of Program
Variable Types
Understanding Memory
Declaring Variables
Simple Commands
Concatenation and Strings
Sleep-Threads-Try Catch
Campus Scenes
Pictures
Java simplified
Application Shell Styles
Reading Data From File
Overview of Applets
Excellent Graphics Applet
Online Reference
Nested if statements
Arrays
Sorting Arrays
Using Strings
Functions
Top 20 Replies 
First program 211
Important Class Example
JAVA in SDK Environment
Understanding OOP
OOP simple example
Recursion example
Example of Inheritance
     and use of JTextArea



*** Web Related **********
Build Student Web Page ?
What is FTP
Download WS ftp95
Download Java Plug In
Applets from jbuilder to sdk
Practice Problems

 

Programming Examples

 

 

                                                

 

Reading Data From a Sequential File

The following code will help both my 211 and 314 students in terms of how to read data from a sequential file.

314 students

 

try
 {
    FileInputStream file_in = new FileInputStream("data314");
    DataInputStream data_in = new DataInputStream(file_in);
    do
       {
          String record = data_in.readUTF();   // UTF is for strings

          CODE TO HANDLE THE STRING DATA
    
          counter ++;
       }  while  ( counter <10);

         REST OF YOUR PROGRAM CODE

   }
catch (IOException e )
   {
      HANDLE ERROR CONDITION  like print message

   }

211 students

 

try
 {
    FileInputStream file_in = new FileInputStream("data1");
    DataInputStream data_in = new DataInputStream(file_in);
    Char race, gender;
    int age, weight;
    int counter=0; 
      DECLARE ALL OTHER COUNTER YOU WILL NEED

   do
       {
          race  = data_in.readChar();
          gender = data_in.readChar();
          age = data_in.readInt();
          weight = data_in.readInt();

          CODE TO HANDLE THE data one record at a time


          counter ++;
       }  while  ( counter <10);

         REST OF YOUR PROGRAM CODE

   }
catch (IOException e )
   {
      HANDLE ERROR CONDITION  like print message

   }