Results 1 to 10 of 10
- 06-25-2011, 03:50 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 3
- Rep Power
- 0
weird character in DataOutputStream file
hello...i'm just new to Java.
I try to make a file (.dat or .txt) file to store Double data value, but after executing the file, I open the file and found weird character in there. It's supposed to be Double datatype value. Can somebody tell me why this happened?
Thanks ^_^
- 06-25-2011, 03:54 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
What was the value in the text file? What was the code to write to the file?(use code tags)
[code]
YOUR CODE HERE
[/code]
-
Last edited by Fubarable; 06-25-2011 at 03:57 PM.
- 06-25-2011, 04:01 PM #4
If you write a double value to a file, it could be written in its binary format. If you want to be able to read the contents of the file you need to convert whatever you write to a String.
- 06-25-2011, 04:28 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
edit: too slow again; what Norm said ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
-
- 06-25-2011, 04:40 PM #7
Member
- Join Date
- Jun 2011
- Posts
- 3
- Rep Power
- 0
Hello again. This is my code ^_^
Java Code:import java.util.*; import javax.swing.*; import java.io.*; class cuba { public static void main(String[] args)throws Exception{ double value[]= {1,2,3,4}; System.out.println(value); double value_double = value[0]+value[1]+value[2]+value[3]; DataOutputStream out = null; try { out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream( "try.dat"))); { out.writeDouble(value_double); } } finally { out.close(); } } }
this is not my original code but it's almost same like this. Can somebody tell me why I get weird character as output and file output. I'm very new to Java and i'm also not a clever student. Thanks for the help ^_^
- 06-25-2011, 04:43 PM #8
Have you read the API doc for the DataOutputStream class and the writeDouble method?
Did you read any of the previous posts on this thread that describe what is happening when your code is executed?
If not, please do.
If you have any questions, about the API doc or the postings please ask.
- 06-25-2011, 04:44 PM #9
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
What did it print to the file? You can look at the API and see how to write a string. you can make the double a string very easily with
Also, consider looking up and using print writer.Java Code:double_value + ""
- 06-25-2011, 04:50 PM #10
Member
- Join Date
- Jun 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Weird problem running a batch file
By d3n1s in forum Advanced JavaReplies: 7Last Post: 06-19-2011, 01:34 AM -
File Download .zip is downloading weird
By hardcorebadger in forum New To JavaReplies: 0Last Post: 02-25-2011, 08:08 PM -
Weird download file problem
By bubbless in forum Advanced JavaReplies: 12Last Post: 05-28-2010, 03:14 PM -
count character in text file as input file
By aNNuur in forum New To JavaReplies: 7Last Post: 03-25-2010, 04:01 PM -
File I/O with DataOutputStream
By Tzaphiel in forum New To JavaReplies: 0Last Post: 12-16-2007, 09:39 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks