You are on page 1of 3

Exercise 23: Write a program in java to read a statement from console, convert it in to

uppercase and again print on console. 


Ans:

import java.io.*;
class s08_04
{
public static void main(String a[]) throws IOException
{
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter file Statement:");
String s1=in.readLine();
System.out.println(s1.toUpperCase());
}
}

Exercise 24: Write a program in java, which takes the name of a file from user, read the
contents of the file and display it on the console.  
Ans:

import java.io.*;
class s08_05
{
public static void main(String args[])
{
FileInputStream fis=null;
Try
{
fis=new FileInputStream(args[0]);
byte ch;
while((ch=(byte)fis.read())!=-1)
{System.out.print((char)ch); }
}
catch(IOException e)
{ System.out.println("interrupted");}
finally
{
try
{fis.close();}
catch(IOException e)
{System.out.println("error in closing");}
}

You might also like