(Created page with "=== Exemplo: Escrita de Leitura Binárias (dados) (Escritor2) === <java5> public class Escritor2 { public static void main(String[] args) throws IOException { try { ...") |
(→Exemplo: Escrita de Leitura Binárias (dados) (Escritor2)) |
||
Line 4: | Line 4: | ||
public class Escritor2 { | public class Escritor2 { | ||
− | public static void main(String[] args) | + | public static void main(String[] args) { |
try { | try { | ||
Line 26: | Line 26: | ||
} | } | ||
− | catch(EOFException e) { | + | catch(EOFException e) { e.printStackTrace(); } |
− | + | catch(IOException e) { e.printStackTrace(); } | |
} | } | ||
<java5> public class Escritor2 {
public static void main(String[] args) {
try {
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("raw.dat")));
out.writeUTF("Valor de PI"); out.writeDouble(Math.PI); out.writeUTF("Raiz quadrada de 2"); out.writeDouble(Math.sqrt(2)); out.close();
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("raw.dat")));
System.out.println(in.readUTF()); System.out.println(in.readDouble()); System.out.println(in.readUTF()); System.out.println(in.readDouble());
} catch(EOFException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } }
} </java5>