Re: Writing Binaries to and Reading Binaries from Disk



KevinSimonson wrote:
I'm planning on writing a program that stores a lot of binary informa-
tion, and I'd like to be able to write it to disk when I'm done with
it, so that later I can read it in from disk again. How do you do
that in Java, write binary <short>s to disk and then later read in
those <short>s from disk again?

Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_

I'm not sure what a binary <short> is but to write a Java short to a stream you can use the DataOutputStream class. Also you can convert it to bytes and use a regular OutputStream. Also see BufferedOutputStream.

import java.io.*;

public class test4 {
public static void main(String[] args) throws IOException {
FileOutputStream fos = new FileOutputStream("data.dat");
DataOutputStream dos = new DataOutputStream(fos);
short s1 = -32768;
dos.writeShort(s1);
dos.close();

FileInputStream fis = new FileInputStream("data.dat");
DataInputStream dis = new DataInputStream(fis);
short s2 = dis.readShort();
dis.close();

System.out.print(s2);
}
}

--

Knute Johnson
email s/nospam/knute2009/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
.



Relevant Pages

  • Re: System not booting!!!
    ... Pri Master HDD error 05/06/2001 ... Download and run the Disk Test program from the web site of the manufacturer ... Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ...
    (microsoft.public.win2000.hardware)
  • Re: iLamp HD upgrade - success!
    ... The installation went without a hitch, although it took me quite a while ... Most of all however I'm delighted about the vast gain in disk space. ... Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ...
    (uk.comp.sys.mac)
  • Re: Windows Installer dialog keeps popping up
    ... Why does the Windows Installer dialog keeps popping up ... Insert 'xxxxxxxx' disk and click OK ... Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ...
    (microsoft.public.win2000.general)
  • Re: copy files with crash
    ... partition on another disk. ... So I copied all files from the first disk and pasted them to the second ... I made the same copy again and got exactly the same crash. ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ...
    (microsoft.public.win2000.general)