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

📄 filesys.java

📁 简易的文件模拟系统
💻 JAVA
字号:
//编制人员:秦星   学号:G0417015
	package pack_filesys;
	import java.io.*;
	import java.*;
	import java.awt.*;
	import java.awt.event.*;
	
	public class FileSys extends WindowAdapter implements ActionListener{
		public Frame ff;
		public File fi;
		public Panel p1,p2;
		public TextArea ta;
		public TextField tf;
		public Button bb;
		public String temp;
	
		public static void main(String args[])throws java.io.IOException{
			FileSys fs=new FileSys();
			fs.init();
		}
	
		public static void run() {//throws java.io.IOException
			FileSys fs=new FileSys();
			if(fs.ff!=null){fs.ff.setVisible(true);}
			else fs.init();
		}
		public void init(){
	
			ff=new Frame("文件系统");
			ff.setLayout(new BorderLayout());
			ff.setSize(500,250);
			ff.setBackground(Color.gray);
			ff.addWindowListener(this);
			p1=new Panel();
			p2=new Panel();
			p1.setBackground(Color.green);
			p2.setBackground(Color.blue);
			ff.add(p1,"North");
			ff.add(p2,"Center");
			ta=new TextArea();
			tf=new TextField();
			tf.setLocation(25,25);
			tf.setSize(30,200);
			tf.setColumns(60);
			p1.setLayout(new FlowLayout());
			p1.add(tf);
			p2.add(ta,"Center");
			bb=new Button("GO");
			p1.add(bb);
			bb.addActionListener(this);
			ff.setVisible(true);
	
		}
		public void filedir(String na){
			fi = new File(na);//directary
			if (fi.exists()){
			  String s[]= fi.list();
			  for(int i=0;i<s.length-1;i++)
			  ta.append("\n"+s[i]);     
			}
			else{
			  ta.append("\n"+"System cann't find the file!"+"\n");
			}
		}
		public void filetype(String na){
		  String s;
		  File f = new File(na);
		  if (f.exists()){
		  try{
		  FileReader fin=new FileReader(f);
		  BufferedReader in = new BufferedReader(fin);
	//      ObjectInputStream s=new ObjectInputStream(fin);
		  while((s=in.readLine())!=null){
			ta.append(s+"\n");//System.out.println(s+"\n");
			//System.out.println(f.getName()+"\n"+f.getPath()+"\n"+f.length()+"\n");
		  }

		 fin.close();
          }catch(Exception se){} 
		 }
		else ta.append("\n"+"System cann't find the file!"+"\n");//System.out.println("system can't find the File");    
		}
		public void actionPerformed(ActionEvent e){
			String comm;//command
			String cont;//content of command
			String temp1,temp2,aa;
			char temp3;
			temp2="";comm="";cont="";
				  temp1=tf.getText().toString();
				  for(int i=0;i<temp1.length();i++){
					temp3=temp1.charAt(i);
					if (temp3==' '){
						comm=temp2;
						i++;
					temp2="";
				   }
				  temp2=temp2+temp1.charAt(i);
				  cont=temp2;
				 }
			if(e.getActionCommand().equals("GO")==true){
				if(comm.equals("dir")){
					try{    filedir(cont);}catch(Exception ea){}
				
				} else{
					if (comm.equals("type")){
					filetype(cont); 
					}else {ta.append("System cann't find the command");
						 //ta.appendText(comm  "System cann't find the command"+);
					 }
				  }
			
			}
		}
		public void windowClosing(WindowEvent e){
			  ff.setVisible(false);
			  //System.exit(0);
			}
	}

⌨️ 快捷键说明

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