Advertisement
jaVer404

level18.lesson03.task02_minByte

Nov 2nd, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package com.javarush.test.level18.lesson03.task02;
  2.  
  3. import java.io.*;
  4. import java.util.ArrayList;
  5.  
  6. /* Минимальный байт
  7. Ввести с консоли имя файла
  8. Найти минимальный байт в файле, вывести его на экран.
  9. Закрыть поток ввода-вывода
  10. */
  11. public class Solution {
  12.     public static void main(String[] args) throws Exception {
  13.  
  14.         String fileName = new BufferedReader(new InputStreamReader(System.in)).readLine();
  15.         FileInputStream fileInputStream = new FileInputStream(fileName);
  16.         ByteArrayOutputStream stream = new ByteArrayOutputStream();
  17.  
  18.         while (fileInputStream.available() > 0) {
  19.             stream.write(fileInputStream.read());
  20.             }
  21.         byte[]bytes=stream.toByteArray();
  22.         byte min=bytes[0];
  23.         for (byte b : bytes) {
  24.             if (b<min) {
  25.                 min=b;
  26.             }
  27.         }
  28.         fileInputStream.close();
  29.         System.out.println(min);
  30.         System.out.close();
  31.         }
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement