Skip to content

Instantly share code, notes, and snippets.

@josinSbazin
Created July 8, 2016 17:19
Show Gist options
  • Save josinSbazin/b5467142ae12d993d41dd24be7eedb08 to your computer and use it in GitHub Desktop.
Save josinSbazin/b5467142ae12d993d41dd24be7eedb08 to your computer and use it in GitHub Desktop.
level18.lesson05.task02
package com.javarush.test.level18.lesson05.task02;
/* Подсчет запятых
С консоли считать имя файла
Посчитать в файле количество символов ',', количество вывести на консоль
Закрыть потоки. Не использовать try-with-resources
Подсказка: нужно сравнивать с ascii-кодом символа ','
*/
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String path;
path = reader.readLine();
reader.close();
FileInputStream fIS = new FileInputStream(path);
int count = 0;
int data;
while (fIS.available()>0) {
data = fIS.read();
if (data==44) count++;
}
fIS.close();
System.out.println(count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment