Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

How do I transfer the information to one file to another and make it all upper case in the second file?

I don't know what to do in this case :(

Are you talking about reading information from a text-file and save it to another text-file?

3 Answers

Yes, I wrote this but I can't get it to work

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

public class ReadandWriteDemo
{
   public static void main(String[] args) throws IOException
   {
      Scanner keyboard= new Scanner(System.in);
      String fileName, fileName1, mericaCaps, line=" ";
      int numLine;

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

      File myFile=new File(fileName);
      Scanner inputFile=new Scanner(myFile);

      while(inputFile.hasNext())
      {
      line=inputFile.nextLine();
      System.out.println(line);
      }

      inputFile.close();

      System.out.print("Enter number of lines: ");
      numLine=keyboard.nextInt();

      keyboard.nextLine();

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

      PrintWriter outputFile=new PrintWriter(fileName1);

      for(int i=1; i<=numLine; i++)
      {
      System.out.println(line.toUpperCase());
      outputFile.println(line);
      }
      outputFile.close();

      System.out.println("Data transfered to new file in Upper Case");
   }
}
'''
My out put is this, but I can not get the new file created to have the sentence in all caps, I actually just get the file address copied to the file

Enter the name of the file: /Users/username/Documents/Java II/June 18 Assigment/'Merica.txt
Freedom above all!!!
Enter number of lines: 1
Enter the file name: /Users/username/Documents/Java II/June 18 Assigment/'MericaCaps
FREEDOM ABOVE ALL!!!
Data transfered to new file in Upper Case

outputFile.println(line); will just copy the line as it is to the output file. If you do the same as in your System.out.println, which is line.toUpperCase() you will get the ALL CAPS that you want. That is --> outputFile.println(line.toUpperCase()); is probably what you are looking for.

Thanks that worked

Excellent!