Upper File Converter
Write a program that asks the user for the names of two files. The first file should be opened for reading and the second file should be opened for writing. The program should read the contents of the first file, change all characters to uppercase, and store the results in the second file. The second file will be a copy of the first file, except that all the characters will be uppercase. Use Notepad or another text editor to create a simple file that can be used to test the program.
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication6; import java.util.Scanner; import java.io.*; /** * * @author uuuuuuu */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException{ Scanner keyboard = new Scanner(System.in); System.out.println("Enter first file name."); String file1 = keyboard.nextLine(); System.out.println("Enter second file name."); String file2 = keyboard.nextLine(); File file = new File(file1); Scanner inputFile = new Scanner(file); PrintWriter outputFile = new PrintWriter(file2); while(inputFile.hasNext()) { file2 = inputFile.nextLine(); outputFile.println(file1.toUpperCase()); System.out.println(file2); } inputFile.close(); outputFile.close(); } }
This is the Notepad file that I used (testfile.txt):
Frankie owned a ferocious feline named Freddy as a pet. Freddy was funny and furry. His fur is bright red with black stripes.
I inserted the statement:
System.out.println
so I can see what is written in file 2.
What is wrong with my code...the output of file 2 is still lowercase.
Why is it still lowercase?