Java IO Stream's File keyboard command-line instance

Source: Internet
Author: User

http://www.verejava.com/?id=17160055387849

Import Java.io.file;import Java.util.scanner;public class Test {private Boolean flag=true;    Private String fileName1;    Private String fileName2;  Public Test () {//Fileutil implement keyboard input command-line program SYSTEM.OUT.PRINTLN ("List Directory contents (dir) or (dir            Directory name) ");            System.out.println ("Create file (mkfile filename)");            System.out.println ("Rename file or directory (rename original file)");            System.out.println ("Delete file (rm file name)");            System.out.println ("Create a level directory (mkdir directory name)");            System.out.println ("Create multilevel directory (mkdirs directory name)");        System.out.println ("Delete directory (rmdir directory name)");        Scanner in=new Scanner (system.in);            while (flag) {String input=in.nextline ();            String[] Inputs=input.split ("");            String Command=inputs[0];            if (inputs.length>=2) {filename1=inputs[1];            } if (inputs.length>=3) {filename2=inputs[2];              }          if ("dir". Equals (command)) {//List Directory contents (dir) dir ();            } if ("Mkfile". Equals (command)) {mkfile ();            } if ("Rename". Equals (command)) {rename ();            } if ("rm". Equals (command)) {rm ();            } if ("MkDir". Equals (command)) {mkdir ();            } if ("Mkdirs". Equals (command)) {mkdirs ();            } if ("RmDir". Equals (command)) {rmdir ();            } if ("Q". Equals (command)) {flag=false;        }}} private void RmDir () {//delete directory (rmdir directory name Fileutil.deletedirs (FILENAME1);    Dir ();        } private void Mkdirs () {//Create multilevel directory (mkdirs directory name) fileutil.createdirs (FILENAME1);    Dir ();     }   private void mkdir () {//Create first level directory (mkdir directory name) Fileutil.createdir (FILENAME1);    Dir ();        } private void Rm () {//delete file (rm file name) Fileutil.deletefile (FILENAME1);    Dir ();        } private void Rename () {//rename file or directory (rename original file New file) Fileutil.renamefile (fileName1, fileName2);    Dir ();        private void Mkfile () {///Create file (mkfile file name) fileutil.createfile (FILENAME1);    Dir ();        } private void Dir () {file Dir=new file (".");        File[] Dirs=dir.listfiles ();            for (int i=0;dirs!=null&&i<dirs.length;i++) {File f=dirs[i];        System.out.println (F.getname ());    }} public static void Main (string[] args) {new Test (); }}

http://www.verejava.com/?id=17160055387849

Java IO Stream's File keyboard command-line instance

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.