What is the wildcard code..?

i am writing a program. I want the program to search for all files that end with one extension, and i want it to rename it to another extension...

example

test.java -> test.dat

(not to encode it.)

ok... i have the actual rename done, but how do i get it to do all files that end with the extension?

here is pretty much the bulk

File z = new File("dv.txt");

z.renameTo(new File("dv.dat"));

that little excerpt renames the file, but how do i get it to do all (filename).txt to (filename).dat with in a directory?

Thank you!

[587 byte] By [pros599a] at [2007-11-26 12:22:00]
# 1
Look into this method in the File class:[url] http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#listFiles()[/url]
CaptainMorgan08a at 2007-7-7 15:14:34 > top of Java-index,Archived Forums,Socket Programming...
# 2
You could also use this one:[url] http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#listFiles(java.io.FileFilter)[/url]You would need to create your own subclass of FileFilter, though.
CaptainMorgan08a at 2007-7-7 15:14:34 > top of Java-index,Archived Forums,Socket Programming...
# 3
i dont exactly understand...lol... i only have the basics down in java...do i need it to read a directory, save it to an array, and rename?
pros599a at 2007-7-7 15:14:34 > top of Java-index,Archived Forums,Socket Programming...
# 4

Create a File instance for the directory.

File directory = new File("C:\\MyDirectory\\");

Create a FilenameFilter that will only accept files with the extension you want.

FilenameFilter filter = new FilenameFilter() {

public boolean accept(File dir, String name) {

return name.matches("*.txt");

}

};

Use listFiles(FilenameFilter) to get an array of File objects that represent every file in the directory that has a name with that extension.

File[] filesToRename = directory.listFiles(filter);

Then iterate over the array changing each file.

kablaira at 2007-7-7 15:14:34 > top of Java-index,Archived Forums,Socket Programming...