I want to read file permissions in unix and write the permissions to a csv file. Here is my code:
static void getFilePermissions(String fileName) {
try {
Process proc = Runtime.getRuntime().exec("ls -lrt "+fileName + "| cut -c1-10");
BufferedReader in = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// getRecursiveFiles("/scratch/samaggar/SampleDir");
getFilePermissions("/scratch/samaggar/SampleDir");
}
It gives me the IOException Kindly suggest.I can't use Java7 which provides built in mechanism.
exec()that takes an array to pass the parameters in.)