Created
July 8, 2016 23:05
-
-
Save josinSbazin/130abc56f9a6dea7c05dbada39e8ec82 to your computer and use it in GitHub Desktop.
level18.lesson10.home01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level18.lesson10.home01; | |
/* Английские буквы | |
В метод main первым параметром приходит имя файла. | |
Посчитать количество букв английского алфавита, которое есть в этом файле. | |
Вывести на экран число (количество букв) | |
Закрыть потоки. Не использовать try-with-resources | |
*/ | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.util.regex.Pattern; | |
public class Solution { | |
public static void main(String[] args) throws IOException { | |
if (args.length<=0) return; | |
String path = args[0]; | |
FileInputStream fis = new FileInputStream(path); | |
Pattern p = Pattern.compile("[a-zA-Z]"); | |
Character c; | |
int count=0; | |
while (fis.available()>0) { | |
c = (char) fis.read(); | |
if (p.matcher(c.toString()).matches()) count++; | |
} | |
fis.close(); | |
System.out.print(count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment