This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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?
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?
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.
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.
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.