Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package dexterJuni;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.util.*;
  6.  
  7. public class Lista {
  8.  
  9.     public static List<byte[]> read(String input) throws IOException{
  10.         //42658374445741237
  11.         List<byte[]> lista = new ArrayList<byte[]>();
  12.         FileInputStream reader = null;
  13.         try {
  14.             reader = new FileInputStream(input);
  15.             int n;
  16.             while((n = reader.read()) != -1) {
  17.                 int intValue = n - '0';
  18.                 byte[] buffer = new byte[intValue];
  19.                 for(int i=0; i<intValue; i++) {
  20.                     buffer[i] = (byte)reader.read();
  21.                 }
  22.                 lista.add(buffer);
  23.             }
  24.         }catch (Exception e) {}
  25.         finally {
  26.             if(reader != null)
  27.                 reader.close();
  28.         }
  29.         return lista;
  30.     }
  31.    
  32.     public static void main(String[] args) throws IOException {
  33.         // TODO Auto-generated method stub
  34.         List<byte[]> lista = read("from.txt");
  35.         System.out.print("[");
  36.         for(byte[] pole: lista) {
  37.             System.out.print("[");
  38.             for(byte b: pole) {
  39.                 System.out.print((char)b);
  40.             }
  41.             System.out.print("]");
  42.         }
  43.         System.out.print("]");
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement