I’m trying to make a simple java program to unhide the ~\Library\ folder on osx using terminal commands. As far as I have researched the code to run system commands from java is
Runtime.getRuntime().exec();
and is listed as such in every place I look it up.
However, my program doesn’t work. Main method below.
public static void main(String[] args) throws IOException {
String[] noHide = {"chflags"," " ,"nohidden"," ", "~/Library/"};
try {
Runtime.getRuntime().exec(noHide);
System.out.println("library unhidden");
} catch (Exception e ) {
e.printStackTrace();
}
}
This program throws no exception, and compiles and executes fine, but the Library folder simply won’t unhide. No matter what I reformat the cmd String. None of the formats below work
String noHide = "chflags nohidden ~/Library";
String[] noHide = {"chflags", "nohidden","~/Library"};
String[] noHide = {"chflags"," " ,"nohidden"," ", "~/Library/"};
If I remove the spaces they throw exceptions (well, not the String array objects). I can run the command (chflags noHidden ~/Library) absolutely fine from the osx terminal. Anyone have an idea why?
You need to use a
tryandcatch, which you have. But, yourmainshould be like this:Basically, you don’t need
throws IOException. This worked for me, so if it still isn’t working in your program, there may be a bigger problem with the way you have something set up.