• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help please, newbie to java and i/o

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a novice at any kind of data i/o. What I want to do:

My Java program generates a series of data values (actually these are pairs of values, let�s call them dataA and dataB.), all as Double type. I want to output these pairs of values to a file, and then plot the data in graphs using an external package. The data are floating-point, e.g dataA =10.1, dataB = 1.075 could be one pair.

My program goes through the multiple entries in an ArrayList, each of which contains unique values of dataA and dataB.

None of the values can be negative.

Previously I have been taking a file produced from another source that had similar data pairs in an ASCII, tab-delimited set of columns, which I could process easily, either automatically into a graphing program, or by exporting / cut-pasting into Excel, etc. If I could reproduce this file format (ASCII, tab-delimited) I would be very happy.

What I�ve attempted so far:
--------------------------------
try{
DataOutputStream output = new DataOutputStream (new FileOutputStream ( "myFile.dat"));

for(int i = 0; i < myArrayList.size(); i++ ) {
simOutput.writeDouble( dataA (i) );
//simOutput.writeDouble( dataB (i) );
}
simOutput.close();
}
catch (IOException e) { }

-----------------------------------

This generates a file that has no formatting (or at least I don�t understand its formatting), and I don�t know how to interpret the gobbledygook in the file. Maybe it contains what I want, but I don�t know.

Any help would be appreciated.

------------------------------------------------------------------------------
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Barbel.
Have a look at the Java API Documentation for DataOutputStream and you'll see:

A data output stream lets an application write primitive Java data types to an output stream in a portable way. An application can then use a data input stream to read the data back in.


No mention of ASCII, so it is probably a bad choice.
A good starting point with IO is the Java Tutorial chapter on Input/Output. Read through it and see if you can find a class which is more in line with your requirements.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic