Professional Documents
Culture Documents
Exercise 23: Write A Program in Java To Read A Statement From Console, Convert It in To Uppercase and Again Print On Console
Exercise 23: Write A Program in Java To Read A Statement From Console, Convert It in To Uppercase and Again Print On Console
Exercise 23: Write A Program in Java To Read A Statement From Console, Convert It in To Uppercase and Again Print On Console
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");}
}