标签:接受数据 文件创建和删除
Scanner scan=new Scanner(System.in);//这是输入语句//下面就是java的创建和删除。注意递归。
public static void deletefiles(File b) {
File []nextfiles=b.listFiles();
for(File temp:nextfiles) {
if(temp.isDirectory()) {
deletefiles(temp);
temp.delete();
}
else if(temp.isFile()) {
temp.delete();
}
}
b.delete();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("插入请输入1,删除请输入2");
Scanner scan0=new Scanner(System.in);
String a=scan0.nextLine();//因為這裡面每次都是接受一次。如果分开写,就得接收好几次。第一次接收完了不等于,那么第二次还会接收。
if(a.equals("1")) {
System.out.println("请输入你要插入的路径");
Scanner scan1=new Scanner(System.in);
String pathinsert=scan1.nextLine();
System.out.println("请输入你要插入的文件的名字");
Scanner scan2=new Scanner(System.in);
String nameinsert=scan2.nextLine();
File files=new File(pathinsert,nameinsert); //注意这里前面是路径后面是文件的名字。
files.mkdirs();
System.out.println(files);
}
else if(a.equals("2")) {
System.out.println("请输入你要删除的路径和名称");
Scanner scan3=new Scanner(System.in);
File files2=new File(scan3.nextLine());
deletefiles(files2);
}else {
System.out.println("您输错啦,重输");
}
}
};
标签:接受数据 文件创建和删除
原文地址:http://blog.51cto.com/13682530/2093925