special characters in file ^@

hi,

i used method tostring to convert a double into string and have written in a file,

while i try to open the file in shell(unix), it shows some special characters as follows,

^@0^@.^@0^@4^@3^@7^@4^@0^@7^@

^@0^@.^@0^@3^@1^@3^@1^@9^@2^@

^@0^@.^@0^@1^@6^@5^@0^@2^@9^@

^@0^@.^@0^@0^@3^@1^@8^@5^@5^@1^@

in between each numbers, when i open the same file in textedit it shows as follows,

0.0655756

0.0976344

also i try to do global substitution using unix commands but shows the message pattern not found.

here's my code what should do to get rid of this trouble,

try{

FileOutputStream fwrite =new FileOutputStream("gridfile.grid");

DataOutputStream dwrite =new DataOutputStream(fwrite);

for(int z=0;z<15;z++){

for(int y=0;y<15;y++){

for(int x= 0;x<15;x++){

doubgrid = Double.toString(filegrid[x][y][z]);

dwrite.writeChars(doubgrid);

dwrite.writeChars("\n");

//System.out.println("raech");

}

}

}

fwrite.close();

[1638 byte] By [prasadgunasa] at [2007-11-27 8:00:56]
# 1
Crossposted: http://forum.java.sun.com/thread.jspa?threadID=5185652
hunter9000a at 2007-7-12 19:43:00 > top of Java-index,Java Essentials,Java Programming...
# 2
i didnt finish what i want to write so reposted it again,sorry for that,
prasadgunasa at 2007-7-12 19:43:00 > top of Java-index,Java Essentials,Java Programming...
# 3
Why do you use a DataOutputStream? I'm pretty sure that's not what you want.
quittea at 2007-7-12 19:43:00 > top of Java-index,Java Essentials,Java Programming...
# 4

> i didnt finish what i want to write so reposted it

> again,

> sorry for that,

That's ok, it's just that two threads means people can spend time answering the question that's already been answered in the other one. The better thing to do in the future would be just make a new post in the original thread.

I see from your code that you're using the default encoding for the output stream. Since you're writing text, a better way would be to use a BufferedWriter wrapped around a Writer:

new BufferedWriter(new OutputStreamWriter(new FileWriter("filename"), "specify the charset here") );

That lets you use a specific encoding instead of relying on the default.

hunter9000a at 2007-7-12 19:43:00 > top of Java-index,Java Essentials,Java Programming...