In this program you will learn how to change the file extension of the file. Here you will be asked to enter the file name whose extension is to be changed and then you will get the file name with the changed extension..
Description of the code:
In the program code given below, you will be asked to enter the file name with the extension as can be observed from the method of java.io.*; package which is BufferedReader();. The compiler will read the file name as oldfileExtension once you enter it through readLine(); method. Then it will check for that filename if it exists or not. If it will find the mentioned filename then change it by asking you to enter a new fileextension. For this we have used a constructor and we have passed the newfileExtension to that. Then we have applied renameTo(); to change the filename. Remember we haven't changed the filename here but file extension only.
The code of the program is given below:
Output of the program:
Please enter the filename with extension to be changed: amit.txt
Enter file extension to change the file type: java
FileExtension has been changed successfully.
Posted on: August 18, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles