我编写了这段代码来隐藏和取消隐藏任何文件或文件夹,但是当用户输入错误时如何显示错误,我尝试使用 else if 但逻辑代码错误,当用户在选择隐藏时输入错误时我想显示错误或取消隐藏,如果用户提供了错误的路径来隐藏或取消隐藏文件。
import java.io.*;
class k
{
public static void main(String args[])
{
String a,h;
boolean q=true;
while(q==true){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nunhide/hide/exit (u/h/e): ");
h=br.readLine();
if("hide".equalsIgnoreCase(h)){
System.out.print("\nwhat you want 2 hide: ");
a=br.readLine();
if(a.equals(a)){
Runtime r=Runtime.getRuntime();
Process p=r.exec("cmd.exe /c attrib +h "+a);
System.out.print("HIDDEN SUCCESSFULLY");
}
//else if(!a.equals(a)){System.out.print("error");}
}else if("unhide".equalsIgnoreCase(h)){
System.out.print("what u want to unhide: ");
a=br.readLine();
if(a.equals(a)){
Runtime r=Runtime.getRuntime();
Process p=r.exec("cmd.exe /c attrib -h "+a);
}
System.out.print("UNHIDDEN SUCCESSFULLY");
}
else if("exit".equalsIgnoreCase(h)){
System.exit(1);
}
}catch(Exception e){
System.out.println(e);
}
}
}
}