Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.utanet.at!newscore.univie.ac.at!aconews-feed.univie.ac.at!aconews.univie.ac.at!not-for-mail Newsgroups: comp.lang.java.programmer From: Andreas Leitgeb Subject: Re: DataInputStream References: <1418dd7f-d5d1-4a2c-b77b-87666f6a9591@k15g2000yqd.googlegroups.com> <9f2a8cFh1nU1@mid.individual.net> <6cf66421-77a9-4088-b810-3bcc958cc8ca@i28g2000yqn.googlegroups.com> Reply-To: avl@logic.at User-Agent: slrn/pre0.9.9-111 (Linux) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: Date: 05 Oct 2011 08:12:46 GMT Lines: 31 NNTP-Posting-Host: gamma.logic.tuwien.ac.at X-Trace: 1317802366 tunews.univie.ac.at 11354 128.130.175.3 X-Complaints-To: abuse@tuwien.ac.at Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8559 bob wrote: > float[] getVertices3(String filename) { > try { > AssetManager am = this.getResources().getAssets(); > InputStream is = am.open(filename); > DataInputStream dis = new DataInputStream(is); > int numfloats=dis.readInt(); > float[] floatArray = new float[numfloats]; > for (int ctr = 0; ctr < floatArray.length; ctr++) { > floatArray[ctr] = dis.readFloat(); > } > return floatArray; Are you aware, that the DataInputStream expects a particular *binary* format of data coming from the stream? If the data stored in the file that you use still contains the same textual representation as for your previous questions, then DataInputStream won't be able to read it properly. You might create a separate converter utility, that reads in your textfile (with StreamTokenizer), then creates a binary file (writing out size and the individual floats through a DataOutputStream. That may seem roundabout, but is just right, if you *casually* need to hand-edit the text-file, but want speed-improved reading into your main application. Another option could be reading the float[] as a single object from an ObjectInputStream. Again. the data for that must have been created before by writing such an array to an ObjectOutputStream.