Write a java program to read the characters from a file, if a character is alphabet then reverse its case, if not then display its category on the Screen. (whether it is Digit or Space)

 import java.util.*;
import java.io.*;
class MyFile
{
File f1;
MyFile()
{
Scanner s = new Scanner(System.in);
System.out.print("Enter the path of file: ");
String path= s.nextLine();
System.out.print("Enter the name of file: ");
String name= s.nextLine();
f1=new File(path, name);
}
void check()
{
try
{
if(f1.isFile() && f1.exists())
{
FileInputStream fobj = new FileInputStream(f1);
int i=fobj.read();
while(i!=-1)
{
if(Character.isDigit((char)i))
{
System.out.println("Character is digit");
}
else if (Character.isSpace((char)i))
{
System.out.println("Character is Space");
}
else
{
if(Character.isUpperCase((char)i))
System.out.println(Character.toLowerCase((char)i));
else
System.out.println(Character.toUpperCase((char)i));
}
i=fobj.read();
}
}
else
{
System.out.println("File doesn't exist");
}
}
catch(Exception e)
{
System.out.print(e);
}
}
}
class slip1
{
public static void main(String args[])
{
MyFile obj = new MyFile();
obj.check();
}
}

0 Comments