如何在JAVA中根据输入文件中的字符数,大写字母和小写字母来读取输入文件和写入输出文件

时间:2018-10-08 20:41:08

标签: exception input output file-processing charactercount

程序应读取input.txt,然后计算字符,大写字母和小写字母的数量。然后应将计数写入输出文件。我该如何计算大写和小写字符,然后将它们传递给输出?

  

输出

     

字符数为36

     

小写字母为13

     

大写字母为5

import java.io.IOException;
import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;
public class FileProcessing 
{
    public static void main(String[] args) throws IOException
    {
       File file1 = new File("input.txt");
        try(Scanner scanner = new Scanner(file1))
        {
                while(scanner.hasNextLine())
                {
                    String s = scanner.nextLine();
                    System.out.println(s);
                }
                scanner.close();
        }
        catch(IOException e)
        {



    }
    File file2 = new File("output.txt");
    try(PrintStream ps = new PrintStream(file2))
    {
        String a = "Number of characters is " + Chars;
        ps.println(a);
        String b = "Number of lower case letters is " + LowLet;
        ps.println(b);
        String c = "Number of upper case letters is " + UppLet;
        ps.println(c);
    }
    catch(IOException e) 
    { 
    }
}
}

0 个答案:

没有答案