User Tools

Site Tools


java:byte_streams_to_data

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
java:byte_streams_to_data [2021/04/04 16:42] – [Μετασχηματισμός των ροών δυαδικών δεδομένων σε βασικούς τύπους δεδομένων] gthanosjava:byte_streams_to_data [Unknown date] (current) – external edit (Unknown date) 127.0.0.1
Line 115: Line 115:
  
 <code java DataInputOutputStreamTest.java> <code java DataInputOutputStreamTest.java>
- 
 import java.nio.*; import java.nio.*;
 import java.io.*; import java.io.*;
Line 135: Line 134:
      
   public static void main(String []args ) {   public static void main(String []args ) {
-    File file = new File("my.bin");+    File file = new File("file.bin");
     write(file);     write(file);
     read(file);     read(file);
Line 143: Line 142:
     int a = -159954;     int a = -159954;
     double b = 125.128953;     double b = 125.128953;
-    char c = 'Ξ';+    char c = 'Θ';
     String str = "Πώς είσαι;";     String str = "Πώς είσαι;";
          
Line 164: Line 163:
       double b = in.readDouble();       double b = in.readDouble();
       char c = in.readChar();       char c = in.readChar();
-      byte [] str = new byte[18]; +      byte [] bytes = new byte[512]; 
-      in.read(str); +      int str_size = in.read(bytes); 
-      ByteBuffer buffer = ByteBuffer.wrap(str); +      
-      System.out.println(new String(str, java.nio.charset.StandardCharsets.UTF_16));+
       System.out.println(a);       System.out.println(a);
       System.out.println(b);       System.out.println(b);
-      System.out.println(c); +      System.out.println("'"+c+"'"); 
-      //System.out.println(str);+      System.out.println(new String(bytes, 0, str_size, java.nio.charset.StandardCharsets.UTF_16));
     }     }
     catch(IOException ex) {     catch(IOException ex) {
Line 179: Line 177:
   }   }
 } }
- 
 </code> </code>
  
java/byte_streams_to_data.1617554549.txt.gz · Last modified: 2021/04/04 15:42 (external edit)