All pastes #1081421 Raw Edit

Mine

public java v1 · immutable
#1081421 ·published 2008-07-24 02:19 UTC
rendered paste body
import java.util.Scanner;import java.io.File;public class RenameExtension {	public static void main(String[] args) {		File directory = new File("C:/test/");		File[] fileNames = directory.listFiles();				Scanner myScanner = new Scanner(System.in);		System.out.print("What is the extension you would like to change? ");		String toChange = myScanner.next();		System.out.print("What is the extension you would like to change it to? ");		String theNewExt = myScanner.next();				for (int i=0; i < fileNames.length; i++) {			String thisFile = fileNames[i].toString();			String fileMinusExt = thisFile.substring(0, thisFile.length() - 3);			if (thisFile.endsWith(toChange)) {				fileNames[i].renameTo(new File(fileMinusExt + theNewExt));				System.out.println(thisFile + " was successfully renamed to " + fileMinusExt + theNewExt);			}		}	}}----------------------------------------------------------------------------------------------------Output:What is the extension you would like to change? txtWhat is the extension you would like to change it to? dllC:\test\Hello World.txt was successfully renamed to C:\test\Hello World.dllC:\test\Test File 2.txt was successfully renamed to C:\test\Test File 2.dllC:\test\TestFile1.txt was successfully renamed to C:\test\TestFile1.dll