📄 createsquentialfile.java
字号:
/**
* Write a description of class CreateSquentialFile here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.io.*;
import java.util.*;
public class CreateSquentialFile
{
// instance variables
private ObjectOutputStream output; // output data to file
private String fileName;
User user; // object to be written to file
String userName;
String passWord;
boolean isAdmin;
ArrayList<Result> result = new ArrayList<Result>();;
/**
* Constructor for objects of class CreateSquentialFile
*/
public CreateSquentialFile(String userName, String passWord, boolean isAdmin, ArrayList<Result> result)
{
// initialise instance variables
this.userName = this.fileName = userName;
this.passWord = passWord;
this.isAdmin = isAdmin;
this.result = result;
}
public void openFile()
{
try //open file
{
output = new ObjectOutputStream(new FileOutputStream("H:\\" + getFileName() + ".usr"));
} // end try
catch(IOException ioException)
{
System.err.println("Error opening file");
}
}
public void setFileName(String f)
{
fileName = f;
}
public String getFileName()
{
return fileName;
}
public void addUserRecord()
{
try
{
user = new User(userName, passWord, isAdmin, result);
output.writeObject(user); // write to file
}
catch (IOException ioException)
{
System.err.println("Error writing to file" + ioException.getMessage());
return;
}
} // end add records
public void closeFile()
{
try
{
if (output != null)
output.close();
}
catch (IOException ioExeception)
{
System.err.println("Error closing file");
System.exit(1);
}
}
public String getUserName()
{
return userName;
}
public String getPassWord()
{
return passWord;
}
public boolean getAdminFlag()
{
return isAdmin;
}
public ArrayList<Result> getResult()
{
return result;
}
} // end class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -