?
Solved

Reding directories using JAVA

Posted on 1999-12-22
3
Medium Priority
?
178 Views
Last Modified: 2010-04-16
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.
0
Comment
Question by:binuts
  • 2
3 Comments
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2300423
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
 
LVL 7

Accepted Solution

by:
Ravindra76 earned 600 total points
ID: 2300460
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
 

Author Comment

by:binuts
ID: 2300868
Thanks Ravindra76. It worked.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month5 days, 10 hours left to enroll

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question