wood burning stoves 2.0*
The moose likes Java in General and the fly likes Search a directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Search a directory" Watch "Search a directory" New topic
Author

Search a directory

Durand Grimmett
Greenhorn

Joined: Jun 02, 2004
Posts: 16
Since no one replied to my other post...I may have come up with a work around, but i still need some assistance.

Does anyone have any sample code, or can anyone point me to any sample code that will search a directory?......Specifically, I need to search a directory for .class files and store those files in a String array.

Thanks in Advance,
DG
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

Nobody replied to your previous post in three hours? Sounds like somebody needs a reminder that patience is a virtue.
I read your previous post. You have the name of a java file. The compiler generates a file with the same name but with a .class extension. Why don't you just change the name of the file you have to end in .class?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Durand Grimmett
Greenhorn

Joined: Jun 02, 2004
Posts: 16
sorry Joe, you're right patience is a virtue!....Im glad you pointed me to that page because I've never read it before. Now that I've been schooled on the proper way to make posts on this site, I will follow the guidelines. Thanks again for your help.

Ok, back to the issue at hand. I don't know if changing the file extension will work for me. I am compiling .java files, and as you know, in return i get .class files. Even if I change the .java extension to .class , is it legal to name my source code xyz.class when its not actually byte code? Or will the compiler still convert my source code to byte code? If so, does it just overwrite the contents of my source code with the byte code, keeping the same name?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

Source code file names must have .java suffixes, class file names must have .class suffixes, and both source and class files must have root names that identify the class. For example, a class called MyClass would be written in a source file called MyClass.java and compiled into a bytecode class file called MyClass.class.

javac - Java Development Kit Tool Documentation
Durand Grimmett
Greenhorn

Joined: Jun 02, 2004
Posts: 16
your quote and my previous post are saying the same thing....which brings me back to the question....What's the benefit of me changing the extension of my source code?......My source code files need the extension .java so that it can be compiled correctly, it doesn't make sense, to change the extension to .class if im actually referring to java source code. All i want to do is gain access to the .class files that are produced after compilation so that I may jar them. This why I was asking if you had any input on searching a directory for .class files and storing them in an Array, then I can pass that array to my Jar method.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

You change the extension of the NAME of the file that you have in your program, not the file itself (extremely simplified example):

If that doesn't make any sense, I'll answer your other question. Have a gander at the classes in the java.io package. File has methods to list directories and FilenameFilter lets you specify what files you are interested in.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Search a directory
 
Similar Threads
Need a simple Java LDAP client
Searching for a string in a file
How to list directory structure under a file server using java and jsp
Zipping subdirs along with files
Zipping Subdirs