0

i want to asking to u. i've tried these syntax in my project file, and it works. but, i wan to change these program to be more powerfull.

here my syntax:

public class Main {

public static void main(String[] args) throws InterruptedException, IOException {

    frame f = new frame();
    f.show();


    File f = new File("D:/lala/coba");

    //System.out.println("insert the username:");
   // hide(f);
}

public static  void hide(File src) throws InterruptedException, IOException {
// win32 command line variant
ProcessPerm p = Runtime.getRuntime().exec("cacls " + src.getPath() + " /E /C /P DINA:n");
p.waitFor(); }}

if i want to change the user "DINA" without write on the syntax, what should i do?

animuson
  • 53,861
  • 28
  • 137
  • 147

1 Answers1

1

Call the java application like java Main scott

with the following code and the user will be scott

public class Main {

public static void main(String[] args) throws InterruptedException, IOException {

    frame f = new frame();
    f.show();


    File f = new File("D:/lala/coba");

    //System.out.println("insert the username:");
   hide(f, args[0]);
}

public static  void hide(File src, String user) throws InterruptedException, IOException {
// win32 command line variant
ProcessPerm p = Runtime.getRuntime().exec("cacls " + src.getPath() + " /E /C /P " + user + ":n");
p.waitFor(); }}
Zecas
  • 647
  • 4
  • 23
  • thanks dude. i'll try it. if i found problem anymore, would you help me again? – Dina Frinsi megasari May 07 '12 at 11:51
  • Sure! if i' don't help you, there is always someone here better than me and ready to help you :P – Zecas May 07 '12 at 13:49
  • well, i have tried your sugest syntax to me, but i'm confuse with String user and args[0]. can u tell me? – Dina Frinsi megasari May 08 '12 at 06:36
  • By now you already know that you are calling your java application as "java arg0 arg1 ... agrn". When you do this the main method of the class passed as argument is called.
    At same time arg0, agr1 up to agrn are delivered to the main method through the single parameter it has: String[]. In your example we are only passing one argument and it will be in available in the first array position [0] (arrays in java are zero-based).
    Then we just pass that value as a new argument for the method where we need it.
    – Zecas May 08 '12 at 08:33