[code=Jaba]
import java.io.*;
public class study {
public static void main(String[] args) {
File directory = new File("C:/Users/Administrator/java");
File[] files = directory.listFiles();
System.out.println(files.length);
for (int i = 0; i < files.length; i++) {
String fileName=files[i].getName();
String prefix=fileName.substring(fileName.lastIndexOf(".")+1);
System.out.println(prefix);
if(prefix != "txt")
{
files[i].renameTo(new File(fileName.substring(0,fileName.lastIndexOf('.'))+".back"));
}
System.out.println(files[i].getName());
}
}
}
[/code]
------解决方案--------------------
字符串比较最好是用equals方法