Advertisement
Wojtekd

Java Sieciowa #1

Nov 8th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.io.DataInputStream;
  2. import java.io.DataOutputStream;
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7.  
  8. public class Main
  9. {
  10.     public static void main(String[] args)
  11.     {
  12.         double[] liczby = { Math.PI, Math.PI/2, 7.5, 2, Math.E };
  13.        
  14.         try(FileOutputStream fos = new FileOutputStream("liczby.dat"))
  15.         {
  16.             DataOutputStream dos = new DataOutputStream(fos);
  17.             for(int i = 0; i < liczby.length; i++)
  18.             {
  19.                 dos.writeDouble(liczby[i]);
  20.             }
  21.             dos.flush();
  22.         }
  23.         catch(IOException e)
  24.         {
  25.             e.printStackTrace();
  26.         }      
  27.        
  28.         try(FileInputStream fis = new FileInputStream("liczby.dat"))
  29.         {
  30.             DataInputStream dis = new DataInputStream(fis);
  31.             while(dis.available() != 0)
  32.             {
  33.                 double current = dis.readDouble();
  34.                 System.out.println(current);
  35.             }      
  36.         }
  37.         catch (IOException e)
  38.         {
  39.             e.printStackTrace();
  40.         }
  41.        
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement