?? modulefile.java
字號:
import java.util.*;
import java.io.*;
/**
* Class to obtain student list from a file.
*
* @author Ian Bradley
* @version 10/03/2007
*/
public class ModuleFile extends Module
{
/**
* Constructor for objects of class ModuleFile
*/
public ModuleFile(String moduleName)
{
super(moduleName);
readModuleList(moduleName);
}
/**
* reads data from a text file
* format name id
*
* @param fileName name of file based on module fileName.txt
*/
private void readModuleList( String fileName)
{
String studentName;
String studentID;
try
{
Scanner fileScanner = new Scanner( new File ( fileName + ".txt"));
while (fileScanner.hasNext())
{
studentName = fileScanner.next();
studentID = fileScanner.next();
addStudent(studentName, studentID);
}
fileScanner.close();
}
catch (IOException e)
{
System.out.println("File not found");
}
}
public void saveModuleList()
{
String fileName = getModuleName() +".txt" ;
try {
PrintWriter print = new PrintWriter(
new BufferedWriter(
new FileWriter( fileName ) ) );
print.println(getAllStudents());
print.close();
}
catch ( IOException iox ) {
System.out.println("Problem writing " + fileName );
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -