本周第三次打卡package OOPexam2;
import java.io.*;
import java.util.*;
/**
* 操作文件的系统类
*
* @author "HuangFan"
* @version 1.0
* @see FolderItem
* @see Folder
* @see File
*
*/
public class FileSystem {
public static ArrayList<FolderItem> folderItemList = new ArrayList<FolderItem>();
/**
* 构造函数
*
*/
public FileSystem() {
}
/**
* 该方法用于读取文件和文件夹信息
*
* @param fileName
*
*/
public static void loadFolderItemFromFile(String fileName) throws FileNotFoundException, IOException {
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String line = reader.readLine();
Date date = new Date();
while(line != null) {
StringTokenizer tokenizer1 = new StringTokenizer(line, "_");
if(tokenizer1.nextToken().charAt(1) == 'o') {
String folderPath = tokenizer1.nextToken();
folderItemList.add(new Folder(tokenizer1.nextToken(), date, 0, new Owner(tokenizer1.nextToken(), tokenizer1.nextToken())));
}
else if(tokenizer1.nextToken().charAt(1) == 'i') {
String filePath = tokenizer1.nextToken();
folderItemList.add(new File(tokenizer1.nextToken(), date, 0, new Owner(tokenizer1.nextToken(), tokenizer1.nextToken()), tokenizer1.nextToken()));
}
line = reader.readLine();
}
reader.close();
}
/**
* 该方法用于展示文件和文件夹信息
*
*/
public static void displayFolderItemInfo() {
PrintWriter stdOut = new PrintWriter(System.out, true);
for(FolderItem item : folderItemList) {
if(item instanceof File) {
stdOut.println(item.getName()+" "+item.getDate()+" "+item.getSize()+" "+item.getOwner().getID()+" "+item.getOwner().getName()+" "+((File) item).getExtension());
}
else if(item instanceof Folder){
stdOut.println(item.getName()+" "+item.getDate()+" "+item.getSize()+" "+item.getOwner().getID()+" "+item.getOwner().getName());
}
}
}
}
|