readsequentialfile.java

来自「一个飞机调度员模拟训练程序,可以添加跑道数量,控制飞机飞行的速度.默认的密码可以」· Java 代码 · 共 97 行

JAVA
97
字号

/**
 * Write a description of class ReadSequentialFile here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */


import java.io.*;

public class ReadSequentialFile
{
    // instance variables - replace the example below with your own
    private ObjectInputStream input;
    private String fileName;

    /**
     * Constructor for objects of class ReadSequentialFile
     */
    public ReadSequentialFile(String fileName)
    {
        // initialise instance variables
        this.fileName = fileName;
    }

    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public void openFile()
    {
        try //opening file
        {
            input = new ObjectInputStream(new FileInputStream("H:\\" + getFileName() + ".usr"));
        } // end try
        catch (IOException ioException)
        {
            System.err.println("Error Opening File.");
        } // end catch
        
    } // opening file
    
    
    public void readATCRecords()
    {
        User user;

        
        try // read from file
        {
            while (true)
            {
                
                user = (User)input.readObject();
                User testUser = new User(user.getUserName(), user.getPassWord(), user.isAdmin(), user.getResults());

            } // while
        }
        catch(EOFException endOfFileException)
        {
            return;
        }
        catch(ClassNotFoundException classNotFoundException)
        {
            System.err.println("Unable to create object.");
        }
        catch(IOException ioException)
        {
            System.err.println("Error during read from file");
        }
        
    } // end reading
    
    public String getFileName()
    {
        return fileName;
    }
     
    public void closeFile()
    {
        try // close file and exit
        {
            if (input != null)
                input.close();
        }
        catch(IOException ioException)
        {
            System.err.println("Error closing file.");
            System.exit(1);
        }
    }
        
            
}

⌨️ 快捷键说明

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