Forums Register Login

Search a directory

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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's weird that we cook bacon and bake cookies. Eat this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1529 times.
Similar Threads
How to list directory structure under a file server using java and jsp
Zipping Subdirs
Searching for a string in a file
Zipping subdirs along with files
Need a simple Java LDAP client
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:31:24.