public static void main(String args[])
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try {
String path=br.readLine();
File f=new File(path);
if(f.isDirectory())//如果是路径
{
File[] l=f.listFiles();
for (File file : l) {
String name=file.getName();
//判断末尾是不是.txt
if(name.substring(name.length()-4, name.length()).equals(".txt"))
{
System.out.println();
//改名
file.renameTo(new File(file.getParent()+"\\"+ name.split(".txt")[0]+".java"));
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
} |