Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

help please, newbie to java and i/o

 
Barbel Kennet
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.

------------------------------------------------------------------------------
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!