99
1010import java .util .Scanner ;
1111import java .io .File ;
12+ import java .nio .file .Path ;
1213
1314
1415public class Filesystem {
15- public static void main (String [] args ) {
16+ public static void main (String [] argv ) {
1617 Scanner scanner = new Scanner (System .in );
1718
18- String argument = "" ;
19+ String a1 = "" ;
20+ String a2 = "" ;
1921 final String prompt = "Jfs> " ;
2022
2123 System .out .print (prompt );
2224
2325 while (scanner .hasNextLine ()) {
2426 String input = scanner .nextLine ();
2527
26- String [] inputArray = input .split (" " );
27- String command = inputArray [0 ];
28+ String [] args = input .split (" " );
29+ String command = args [0 ];
2830
29- if (inputArray .length > 1 ) {
30- argument = inputArray [1 ];
31- } else {
32- argument = "" ;
31+ if (args .length > 1 ) {
32+ a1 = args [1 ];
33+ }
34+ if (args .length > 2 ) {
35+ a2 = args [2 ];
3336 }
3437
3538 if (command .equals ("exit" ) || command .equals ("q" ) || command .equals ("\u0004 " )) {
3639 break ;
3740 } else if (command .equals ("java_version" )) {
3841 System .out .println (System .getProperty ("java.version" ));
3942 } else if (command .equals ("absolute" )) {
40- System .out .println (absolute (argument ));
43+ System .out .println (absolute (a1 ));
44+ } else if (command .equals ("create_symlink" )) {
45+ System .out .println (create_symlink (a1 , a2 ));
4146 } else if (command .equals ("expanduser" )) {
42- System .out .println (expanduser (argument ));
47+ System .out .println (expanduser (a1 ));
4348 } else if (command .equals ("canonical" )) {
44- System .out .println (canonical (argument ));
49+ System .out .println (canonical (a1 ));
4550 } else if (command .equals ("parent" )) {
46- System .out .println (parent (argument ));
51+ System .out .println (parent (a1 ));
4752 } else if (command .equals ("root" )) {
48- System .out .println (root (argument ));
53+ System .out .println (root (a1 ));
4954 } else if (command .equals ("is_absolute" )) {
50- System .out .println (is_absolute (argument ));
55+ System .out .println (is_absolute (a1 ));
5156 } else if (command .equals ("is_exe" )) {
52- System .out .println (is_exe (argument ));
57+ System .out .println (is_exe (a1 ));
5358 } else if (command .equals ("is_readable" )) {
54- System .out .println (is_readable (argument ));
59+ System .out .println (is_readable (a1 ));
5560 } else if (command .equals ("ram_free" )) {
5661 System .out .println (ram_free ());
5762 } else if (command .equals ("cpu_count" )) {
@@ -71,6 +76,18 @@ public static String absolute(String path) {
7176 return f .getAbsolutePath ();
7277 }
7378
79+ public static Boolean create_symlink (String target , String link ) {
80+ Path t = new File (target ).toPath ();
81+ Path l = new File (link ).toPath ();
82+ try {
83+ java .nio .file .Files .createSymbolicLink (l , t );
84+ return true ;
85+ } catch (java .io .IOException e ) {
86+ System .err .println (e );
87+ return false ;
88+ }
89+ }
90+
7491 public static String expanduser (String path ) {
7592 if (path .startsWith ("~" ))
7693 return System .getProperty ("user.home" ) + path .substring (1 );
0 commit comments