I used DataStream to write some primitive type data to a file, and then read it back. The data was read back and displayed on the console fine, but when i saw the file i was writing to i found lots of special characters- pounds signs and all. Here is the code :
Please help!import java.io.*; class Data{ static final double[] prices = {12.22,11.11,13.33,14.44,15.55}; static final int[] qtys = {1,2,3,4,5}; static final String[] descs = {"space shuttle", "titan", "cassini", "black hole", "proxima centauri"}; public static void main(String ...arg) throws Exception{ DataOutputStream o = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Cosmos.txt"))); for(int i=0;i<5;i++){ o.writeDouble(prices[i]); o.writeInt(qtys[i]); o.writeUTF(descs[i]); } o.close(); DataInputStream di = new DataInputStream(new BufferedInputStream(new FileInputStream("Cosmos.txt"))); double price; int qty; String desc; try{ while(true){ price = di.readDouble(); qty = di.readInt(); desc = di.readUTF(); System.out.format("You Ordered %d units of %s at Rs.%.2f %n", qty, desc, price); System.out.println(); } }catch(EOFException e){ System.out.println("Done!!"); } di.close(); } }