Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!feeder.news-service.com!aioe.org!.POSTED!not-for-mail From: Roedy Green Newsgroups: comp.lang.java.programmer Subject: Re: DataInputStream Date: Thu, 06 Oct 2011 02:48:40 -0700 Organization: Canadian Mind Products Lines: 38 Message-ID: <6vtq8799uup4maagr4e2fj6na1hcg37dbl@4ax.com> References: <1418dd7f-d5d1-4a2c-b77b-87666f6a9591@k15g2000yqd.googlegroups.com> Reply-To: Roedy Green NNTP-Posting-Host: RCd/Ul4tyxGUBII8WGwa5g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Forte Agent 6.00/32.1186 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8593 On Tue, 4 Oct 2011 22:34:56 -0700 (PDT), bob wrote, quoted or indirectly quoted someone who said : >I want to use DataInputStream to read into a float[]. Anyone know how >to do this? In Java, with DataInputStream you have to think in terms of reading primitives, not records as you would in C++ or COBOL. You would read a count followed by n floats, one field at a time. Ask http://mindprod.com/jgloss/fileio.html to generate you the code. You can logically read and write entire objects including arrays with dependent contents using serialization. See http://mindprod.com/jgloss/serialization.html again http://mindprod.com/jgloss/fileio.html will generate you sample code. Part of the reason is Java as WORA. The I/O has to work whether the machine is internally in big or little ended. the run time has to convert on a field by field basis. Java can't treat objects/records as just a blob of bytes the way earlier machine-dependent languages can. It is a lot easier to let java determine the exact binary layout of files rather that trying to read some bizarre format created elsewhere. Then you have to read byte by byte with an InputStream. -- Roedy Green Canadian Mind Products http://mindprod.com It should not be considered an error when the user starts something already started or stops something already stopped. This applies to browsers, services, editors... It is inexcusable to punish the user by requiring some elaborate sequence to atone, e.g. open the task editor, find and kill some processes.