package june29;
import java.io.FileInputStream;
import java.util.Scanner;
public class input_from_file {
public static void main(String[] args) throws Exception
{
Scanner sc = new Scanner(System.in);
System.out.print("enter a file name with full path: ");
String filePath=sc.nextLine();
FileInputStream fis=new FileInputStream(filePath);
int bytes=fis.available();
int alphaUpper=0, alphaLower=0, numeric=0, space=0, line=1;
System.out.println("showing file data ->");
while(true)
{
int var=fis.read();
if(var==-1) {
break;
}
if(var>='A' && var<='Z') {
alphaUpper++;
}
else if(var>='a' && var<='z') {
alphaLower++;
}
else if(var>='0' && var<='9') {
numeric++;
}
else if(var==' ') {
space++;
}
else if(var=='\n') {
line++;
}
System.out.print((char)var);
}
System.out.println("\n---------------------------------------------");
System.out.println("Details of file "+filePath+"->");
System.out.println("Alphabets in uppercase: "+alphaUpper);
System.out.println("Alphabets in lowercase: "+alphaLower);
System.out.println("Total Alphabets: "+(alphaLower+alphaUpper));
System.out.println("Numerics: "+numeric);
System.out.println("Spaces: "+space);
System.out.println("Lines: "+line);
System.out.println("file size: "+bytes+" bytes");
System.out.println("---------------------------------------------");
fis.close();
}
}
import java.io.FileInputStream;
import java.util.Scanner;
public class input_from_file {
public static void main(String[] args) throws Exception
{
Scanner sc = new Scanner(System.in);
System.out.print("enter a file name with full path: ");
String filePath=sc.nextLine();
FileInputStream fis=new FileInputStream(filePath);
int bytes=fis.available();
int alphaUpper=0, alphaLower=0, numeric=0, space=0, line=1;
System.out.println("showing file data ->");
while(true)
{
int var=fis.read();
if(var==-1) {
break;
}
if(var>='A' && var<='Z') {
alphaUpper++;
}
else if(var>='a' && var<='z') {
alphaLower++;
}
else if(var>='0' && var<='9') {
numeric++;
}
else if(var==' ') {
space++;
}
else if(var=='\n') {
line++;
}
System.out.print((char)var);
}
System.out.println("\n---------------------------------------------");
System.out.println("Details of file "+filePath+"->");
System.out.println("Alphabets in uppercase: "+alphaUpper);
System.out.println("Alphabets in lowercase: "+alphaLower);
System.out.println("Total Alphabets: "+(alphaLower+alphaUpper));
System.out.println("Numerics: "+numeric);
System.out.println("Spaces: "+space);
System.out.println("Lines: "+line);
System.out.println("file size: "+bytes+" bytes");
System.out.println("---------------------------------------------");
fis.close();
}
}
Comments
Post a Comment