Convert any file to uppercase Learn programming Java

Lesson:

File Management


Exercise:

Convert any file to uppercase


Objetive:

Write a program to read a file (of any kind) and dump its content to another file, changing the lowercase letters to uppercase.

You must deliver only the ".cs" file, with you name in a comment.


Code:

public class Main
{
    public static void main(String[] args)
	{
		BinaryReader inFile = new BinaryReader(File.Open("example.exe", FileMode.Open));

		BinaryWriter outFile = new BinaryWriter(File.Open("example.exe.upper", FileMode.Create));

		long filesize = inFile.BaseStream.getLength();

		for (long i = 0; i < filesize; i++)
		{
			byte b = inFile.ReadByte();

			if ((b >= (byte)'a') && (b <= (byte)'z'))
			{
				b -= 32;
			}
			outFile.Write(b);
		}
		inFile.Close();
		outFile.Close();
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.