Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Uppercase File Converter Write a program that asks the user for the names of two

ID: 3606573 • Letter: U

Question

Uppercase 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.

I have the following:

import java.io.*;
import java.util.Scanner;

public class low_To_UP
{
public static void main(String[] args) throws IOException
{
Scanner keyboard = new Scanner(System.in);
String inputFile;
String outputFile;
String writeToFile;

System.out.print("Enter the input file name: ");
inputFile = keyboard.nextLine();

System.out.print("Enter the output file name: ");
outputFile = keyboard.nextLine();

FileReader fileRead = new FileReader(inputFile);
BufferedReader inputFileNew = new BufferedReader(fileRead);

FileWriter fwriteToFile = new FileWriter(outputFile);
PrintWriter outputFileNew = new PrintWriter(fwriteToFile);

  
while ((writeToFile = inputFileNew.readLine()) != null)
{
System.out.println(writeToFile);
  
writeToFile = inputFileNew.readLine();
String upper = writeToFile.toUpperCase();
System.out.println(upper);
outputFileNew.println(upper);
}
  
  
inputFileNew.close();
outputFileNew.close();
}
}
How would I be able to do this program without the BufferedReader method?   

Explanation / Answer

You can do using Scanner Object.

import java.io.*;

import java.util.Scanner;

public class low_To_UP

{

   public static void main(String[] args) throws IOException

   {

       Scanner keyboard = new Scanner(System.in);

       String inputFile;

       String outputFile;

       String writeToFile;

       System.out.print("Enter the input file name: ");

       inputFile = keyboard.nextLine();

       System.out.print("Enter the output file name: ");

       outputFile = keyboard.nextLine();

      

       keyboard.close();

      

       Scanner fileScanner = new Scanner(new File(inputFile));

       FileWriter fwriteToFile = new FileWriter(outputFile);

       PrintWriter outputFileNew = new PrintWriter(fwriteToFile);

       while (fileScanner.hasNextLine())

       {

           writeToFile = fileScanner.nextLine();

           System.out.println(writeToFile);

           String upper = writeToFile.toUpperCase();

           System.out.println(upper);

           outputFileNew.println(upper);

       }

       fileScanner.close();

       outputFileNew.close();

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote