Forum Stats

  • 3,837,210 Users
  • 2,262,237 Discussions
  • 7,900,223 Comments

Discussions

DataIO Streams

807569
807569 Member Posts: 34,691
What is the importance DataInputStream and DataOutputStream....???

How can i write a human readable file, that contains double,int,String values...
I tried it with DataOutputStream...But it is not human readable....(possible to read from DataInputStream)

How can i create a human readable file ??? (By using Writer or OutputStream)

//"MyFile.txt" data should contain in a tabular format.(like this,..)

price unit descs
19.99 12 Java T-shirt
9.99 8 Java Mug
15.99 13 Duke Juggling Dolls
3.99 29 Java Pin
4.99 50 Java Key Chain
import java.io.*;

public class DataIOStream{
   public static void main(String args[]) throws Exception{
	
    DataOutputStream out = new DataOutputStream(new FileOutputStream("MyFile.txt"));
	
	double[] prices = { 19.99, 9.99, 15.99, 3.99, 4.99 };
        int[] units = { 12, 8, 13, 29, 50 };
        String[] descs = { "Java T-shirt",
			   "Java Mug",
			   "Duke Juggling Dolls",
			   "Java Pin",
			   "Java Key Chain" };

	
	for(int i=0;i<prices.length;i++){
	    out.writeDouble(prices<em>);<br />
out.writeChar('\t');<br />
out.writeInt(units[i]);<br />
out.writeChar('\t');<br />
out.writeChars(descs[i]);<br />
out.writeChar('\n');<br />
	<br />
	}<br />
	out.close();<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
<br />
:-) </em>
This discussion has been closed.