Java exec executeLS()

Here you can find the source of executeLS()

Description

execute LS

License

Open Source License

Declaration

public static String executeLS() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    public static final String ROOT = "user.dir";

    public static String executeLS() {
        // TODO Auto-generated method stub
        //ArrayList<String> fileNames = new ArrayList<String>();
        StringBuilder directoryList = new StringBuilder();

        try {/*  w  w  w  .jav a  2 s  .  c  o m*/

            File files = new File(executePWD());
            File[] fList = files.listFiles();
            for (File f : fList)
                directoryList.append(f.getName() + "\t");
            //fileNames.add(f.getName());

        } catch (Exception e) {
            System.out.println("----Exception in LS command execution -----" + e.getMessage());
        }
        return directoryList.toString();
    }

    public static String executePWD() {
        // TODO Auto-generated method stub
        String currentDirectory = null;
        try {
            currentDirectory = System.getProperty(ROOT);
        } catch (Exception e) {
            System.out.println("----Exception in PWD command execution -----" + e.getMessage());
        }
        return currentDirectory;
    }
}

Related

  1. executeDotCommand(final File dotFile)
  2. executeGET(DataInputStream sockInp, DataOutputStream sockOutp)
  3. executeGetStatus(ProcessBuilder pb)
  4. executeIt(String command)
  5. executeLocalCommand(String[] command)
  6. executeMemoryInfoProcess(String... command)
  7. executeNativeCommand(String command)
  8. executeProcess(final File workDir, final String... termArray)
  9. executeProcess(final String[] cmds)