⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 driver.java

📁 用java写的unix文件管理模拟系统
💻 JAVA
字号:
import java.io.*;

public class Driver
{
	public static void main(String[] args) throws Exception 
	{
		//program start
		boolean logsuce=false;
		System.out
				.println("/********************欢迎使用unix文件模拟系统********************/");
		for (int i = 0; i < 4; i++) 
		{
			System.out.print("please enter your username: ");
			InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader br = new BufferedReader(isr);

			String username = br.readLine();
			SystemInformation.currentuser=username;
			// System.out.println(username);

			System.out.print("please enter your password: ");
			InputStreamReader isr2 = new InputStreamReader(System.in);
			BufferedReader br2 = new BufferedReader(isr2);
			String password = br2.readLine();
			// System.out.println(password);
			Command comm = new Command();
			if (comm.login(username, password)) 
			{
				System.out
						.println("/********************登入成功,系统正在初始化********************/");
				logsuce=true;
				break;
			} else
				System.out
						.println("/********************用户名或密码不正确,请重新输入********************/");
			if(i==3)
			{
				System.out.println("你输入密码错误次数太多,系统即将自动结束!");
				logsuce=false;
			}
		}
		
		
		
		if (logsuce) 
		{

			System.out
					.println("/********************系统初始化完毕********************/");
			SystemInformation.cur_dir = "root";
			SystemInformation.father_dir = null;
			SystemInformation.cur_id = 0;
			SystemInformation.fa_id = 0;
			SystemInformation.path = "root";
			System.out.print(SystemInformation.path + "/:");
			Command comm = new Command();
			// command
			while (true) 
			{
				InputStreamReader isr = new InputStreamReader(System.in);
				BufferedReader br = new BufferedReader(isr);
				String cmd = br.readLine();
				String result[] = cmd.split(" ");
				// command
				if (result[0].equals("ls")) 
				{
					comm.ls();
					System.out.print(SystemInformation.path + "/:");
				}
				if (result[0].equals("cd")) 
				{
					comm.cd(result[1]);
					System.out.print(SystemInformation.path + "/:");
				}
				if (result[0].equals("pwd")) 
				{
					comm.pwd();
					System.out.print(SystemInformation.path + "/:");
				}
				if (result[0].equals("cat")) 
				{
					boolean createnewfile;
					if (result[1].equals(">")) 
					{
						createnewfile = true;
						comm.cat(result[2], createnewfile);
					} else 
					{
						createnewfile = false;
						comm.cat(result[1], createnewfile);
					}
					System.out.print(SystemInformation.path + "/:");
				}
				if (result[0].equals("mkdir")) 
				{
					comm.mkdir(result[1]);
					System.out.print(SystemInformation.path + "/:");
				}
				if (result[0].equals("rmdir")) 
				{
					System.out
							.println("你确实要删除这个目录吗?该目录下可能还有其他目录或文件,按y/Y表示是,按n/N表示否");
					InputStreamReader isr2 = new InputStreamReader(System.in);
					BufferedReader br2 = new BufferedReader(isr2);
					String answer = br2.readLine();
					if (answer.equals("y") || answer.equals("Y")) 
					{
						comm.rmdir(result[1]);
					}
					System.out.print(SystemInformation.path + "/:");
				}
				if (result[0].equals("rm")) 
				{
					System.out.println("你确实要删除此文件吗?按y/Y表示是,按n/N表示否");
					InputStreamReader isr3 = new InputStreamReader(System.in);
					BufferedReader br3 = new BufferedReader(isr3);
					String answer = br3.readLine();
					if (answer.equals("y") || answer.equals("Y")) 
					{
						comm.rm(result[1]);
					}
					System.out.print(SystemInformation.path + "/:");
				}
				if (result[0].equals("passwd")) 
				{
					comm.passwd(SystemInformation.currentuser, result[1]);
					System.out.print(SystemInformation.path + "/:");
				}
				if (result[0].equals("mv")) 
				{
					comm.mv(result[1], result[2]);
					System.out.print(SystemInformation.path + "/:");
				}

				if (result[0].equals("cp")) 
				{
					comm.cp(result[1], result[2]);
					System.out.print(SystemInformation.path + "/:");
				}
				if (result[0].equals("chmod")) 
				{
					comm.chmod(result[1], result[2]);
					System.out.print(SystemInformation.path + "/:");
				}
				if (result[0].equals("chown")) 
				{
					comm.chown(result[1], result[2]);
					System.out.print(SystemInformation.path + "/:");
				}
				if (result[0].equals("chgrp")) 
				{
					comm.chgrp(result[1], result[2]);
					System.out.print(SystemInformation.path + "/:");
				}
				if(result[0].equals("logout"))
				{
					comm.logout();
					break;
				}
			}
		}
		System.out.println("系统已退出");
	}
}

⌨️ 快捷键说明

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