Didart

Read File

Jan 24th, 2023 (edited)
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. package StreamsFilesAndDirectories4;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.util.Scanner;
  7.  
  8. public class ReadFile {
  9.     public static void main(String[] args) throws IOException {
  10.         Scanner scanner = new Scanner(System.in);
  11.  
  12.         String path = "input.txt";
  13.  
  14.         try (InputStream fileInputStream = new FileInputStream(path)){
  15.             int oneByte = fileInputStream.read();
  16.  
  17.             while (oneByte >= 0) {
  18.                 System.out.printf("%s ", Integer.toBinaryString(oneByte));
  19.                 oneByte = fileInputStream.read();
  20.             }
  21.         } catch (IOException e) {
  22.             e.printStackTrace();    
  23.         }finally {
  24.  
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment