⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cw2a.java

📁 samll awt programs for the beginner.
💻 JAVA
字号:
/**
* Author: Jing Han
* Date; 12/11/03
*Module: G6DICp
* Title: ICP Coursework 2
* SCSiT Username: jxh23m
*/



import java.util.*;
import java.io.*;

class cw2a
{
    public static void main(String[] arg)
    {
       
        //prompt for filename
        System.out.print("Enter data file:"+"  ");
        String filename=TButils.readln();
        
        //declare varialbe title and instantiate vector
        String title = "";
        Vector data=new Vector();
        
        //instantiate RandomAeccessFile. myData file is opened for reading
        try 
        {
            RandomAccessFile inFile=new RandomAccessFile(filename,"r");
            String line; //a string to contain the line read
            int lineNo=0;//initialise the line number of file
            
            // use the readLine method to read a line into the string line until the end of the file
            while((line=inFile.readLine())!=null) 
            {
               
                if( lineNo == 0 )
                {
                    title=line;
                 }// for store the first line into title
                else
                {
                    data.addElement(line);
                }// store the rest of file into vector
                
                lineNo++; //lineNo increases every while loop            
            }//end of while loop 
         }// end of try 
         catch (IOException e)
         {
            System.out.println("An i/o error has occured ["+e+"]");
         }// end of catch exception
         
         
         System.out.println("Title:"+"  "+title);// print out title
         
         // use for loop to print out elements in the vector
         for(int n=0;n<data.size();n++)
         {
             System.out.println(data.elementAt(n));
         }
         System.out.println();
    }   
}     
        
        
        
        
        
 

        
        
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -