joseleonweb

Untitled

Feb 28th, 2021
525
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2.  
  3. class RWData {
  4.     public static void main(String[] args) {
  5.         int i = 10;
  6.         double d = 1023.56;
  7.         boolean b = true;
  8.        
  9.         // Write some values.
  10.         try (DataOutputStream dataOut =
  11.                 new DataOutputStream(new FileOutputStream("testdata")))
  12.         {
  13.             System.out.println("Writing " + i);
  14.             dataOut.writeInt(i);
  15.            
  16.             System.out.println("Writing " + d);
  17.             dataOut.writeDouble(d);
  18.            
  19.             System.out.println("Writing " + b);
  20.             dataOut.writeBoolean(b);
  21.            
  22.             System.out.println("Writing " + 12.2 * 7.4);
  23.             dataOut.writeDouble(12.2 * 7.4);
  24.         }
  25.         catch(IOException exc) {
  26.             System.out.println("Write error.");
  27.             return;
  28.         }
  29.        
  30.         System.out.println();
  31.        
  32.         // Now, read them back.
  33.         try (DataInputStream dataIn =
  34.                 new DataInputStream(new FileInputStream("testdata")))
  35.         {
  36.             i = dataIn.readInt();
  37.             System.out.println("Reading " + i);
  38.            
  39.             d = dataIn.readDouble();
  40.             System.out.println("Reading " + d);
  41.            
  42.             b = dataIn.readBoolean();
  43.             System.out.println("Reading " + b);
  44.            
  45.             d = dataIn.readDouble();
  46.             System.out.println("Reading " + d);
  47.         }
  48.         catch(IOException exc) {
  49.             System.out.println("Read error.");
  50.         }
  51.     }
  52. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×