📄 readsequentialfile.java
字号:
/**
* 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -