Reding directories using JAVA

I would like to know, how to read directories and search through the files in it using JAVA. Also i want to know how to get the permissions for each files in the directory. All your comments regarding this are welcome.
binutsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ravindra76Commented:
Hi,

See the documentation of your systems
c:\java_hone\src\java\io\File.java

It has all methods.
list() - Listing all files
isDIrectory() - Is directoy
isFile() - Isa file
canRead() - Is file readable
canWrite() - Is writable.

Best of luck
0
Ravindra76Commented:
Hi,

sample code.

import java.io.*;

class Dir{
      public static void main(String args[]) {

            try {
                  
                  File f = new File("c:\\samples");
                  System.out.println("IS directory:"+f.isDirectory());
                  System.out.println("IS file:"+f.isFile());
                  String files[] = f.list();
                  for ( int i=0; i < files.length; i++ ) {
                        System.out.print(files[i]);
                        System.out.print("::Writable:"+(new File(files[i]).canWrite()));
                        System.out.print("::Readable:"+(new File(files[i]).canRead()));
                        System.out.println();
                  }
            }
            catch ( Exception ee) {
                  ee.printStackTrace();
                        
            }
            
     }
}

Best of luck
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
binutsAuthor Commented:
Thanks Ravindra76. It worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.