So, I have this assignment to read the text from one file and write to another, changing all the text to uppercase. I'm not sure why, but when I run it, it freezes after I enter the file to write to. Any help is greatly appreciated.
import java.io.*;
import java.util.Scanner;
public class McKinneyBenjaminUpperFile
{
public static void main(String [] args)throws IOException
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Benjamin's Uppercase File Converter\n");
String file1;
String file2;
System.out.println("Enter the name of the file to read from.");
file1 = keyboard.nextLine();
File file1open = new File(file1);
if(!file1open.exists())
{
System.out.println("The file you entered does not exists.");
System.exit(0);
}
Scanner infile = new Scanner(file1);
System.out.println("Enter the name of the file to write to: ");
file2 = keyboard.nextLine();
File file2open = new File(file2);
if(file2open.exists())
{
System.out.println("The file you entered already exists.");
System.exit(0);
}
PrintWriter outfile = new PrintWriter(file2);
while(infile.hasNext())
{
for(int i=0;i<file2open.length();i++)
{
String line = infile.nextLine().substring(0,1);
String newLine = line.toUpperCase();
outfile.println(newLine);
}
}
System.out.println("Conversion complete. " + file1 + " is now converted to all uppercase in " + file2);
}
}