Java program that prompts the user for a drive letter, a path, a file name, and a extension then print the complete file name
Posted by Samath
Last Updated: February 09, 2021

File names and extensions. Write a Java program that prompts the user for the drive letter ( C ), the path ( \Windows\System ), the file name ( Readme ), and the extension ( txt ). Then print the complete file name  C:\Windows\System\Readme.txt . (If you use UNIX or a Macintosh, skip the drive name and use  / instead of \ to separate directories.)

Sample Output:
Please enter the drive letter: C                                                                                                                                                           
Please enter the path: programs                                                                                                                                                            
Please enter the filename: game                                                                                                                                                            
Please enter the extension: exe                                                                                                                                                            


import java.util.Scanner;

public class Main
         public static void main(String[] args) {
            Scanner in = new Scanner(;
            System.out.print("Please enter the drive letter: ");
            String driveLetter =;
            System.out.print("Please enter the path: ");
            String path =;
            System.out.print("Please enter the filename: ");
            String filename =;
            System.out.print("Please enter the extension: ");
            String extension =;
            String completeFilename = driveLetter +":"+ "\\"  + path + "\\" + filename + "." + extension;