import java.util.Scanner; import java.io.File; public class ReadFromFile { public static void main(String[]args) throws FileNotFoundException{ File CS101 = new File("C:\\password.txt"); //"" it should be the path where you saved the text file Scanner scn = new Scanner(CS101); String password = scn.nextLine(); System.out.println("The password is "+ password); } }