如何继续制作 in - BlueJ Java 文件管理器
How to proceed with making an in - BlueJ Java file manager
我知道这有点菜鸟程序,但我慢慢地感到困惑。 'down' 函数将像 cd 一样工作,而 'up' 函数将像 cd 一样工作..
我不知道如何允许用户创建文件或文件夹。我尝试使用 arrayLists 而不是数组,但无法解决错误。任何帮助将不胜感激。
import java.util.Scanner;
class FileManager {
//array of arrays will go here
String Dir[] = {"UserOne"};
String SystemFolders [] = {"Documents","","",};
String SubFiles [] = {"","","","","",""};
String Nav [][] = { Dir, SystemFolders, SubFiles};
int levelCounter = 0;
public void main(String[]args) {
Scanner sc = new Scanner (System.in);
System.out.println("Enter a command");
String command = sc.next();
if (command.compareTo("down") == 0)
down();
//else if is on the way
}
void down () {
//This will execute when the command is 'down'
System.out.println(Nav[++levelCounter]);
}
void up () {
//This will execute when the command is 'up'. It acts like cd..
System.out.println(Nav[--levelCounter]);
}
}
如果这是您程序的入口点,那么您需要将 main
方法声明为静态方法,例如
public static void main(String[] args)
然后要在主方法中访问 FileManager
class 中的方法,您需要在主方法中创建 class 的实例。像这样
public static void main(String[]args) {
FileManager fm = new FileManager(); // Creates an instance
Scanner sc = new Scanner (System.in);
System.out.println("Enter a command");
String command = sc.next();
if (command.equals("down")) // equals will suffice in this case
// or equalsIgnoreCase() if you dont want case to be a problem
fm.down(); // Notice now this calls the down method from the instance
//else if is on the way
}
然后看这个例子create files or this to create folders
我知道这有点菜鸟程序,但我慢慢地感到困惑。 'down' 函数将像 cd 一样工作,而 'up' 函数将像 cd 一样工作..
我不知道如何允许用户创建文件或文件夹。我尝试使用 arrayLists 而不是数组,但无法解决错误。任何帮助将不胜感激。
import java.util.Scanner;
class FileManager {
//array of arrays will go here
String Dir[] = {"UserOne"};
String SystemFolders [] = {"Documents","","",};
String SubFiles [] = {"","","","","",""};
String Nav [][] = { Dir, SystemFolders, SubFiles};
int levelCounter = 0;
public void main(String[]args) {
Scanner sc = new Scanner (System.in);
System.out.println("Enter a command");
String command = sc.next();
if (command.compareTo("down") == 0)
down();
//else if is on the way
}
void down () {
//This will execute when the command is 'down'
System.out.println(Nav[++levelCounter]);
}
void up () {
//This will execute when the command is 'up'. It acts like cd..
System.out.println(Nav[--levelCounter]);
}
}
如果这是您程序的入口点,那么您需要将 main
方法声明为静态方法,例如
public static void main(String[] args)
然后要在主方法中访问 FileManager
class 中的方法,您需要在主方法中创建 class 的实例。像这样
public static void main(String[]args) {
FileManager fm = new FileManager(); // Creates an instance
Scanner sc = new Scanner (System.in);
System.out.println("Enter a command");
String command = sc.next();
if (command.equals("down")) // equals will suffice in this case
// or equalsIgnoreCase() if you dont want case to be a problem
fm.down(); // Notice now this calls the down method from the instance
//else if is on the way
}
然后看这个例子create files or this to create folders