• Post Reply Bookmark Topic Watch Topic
  • New Topic

writing to a text file from cmmand prompt

 
Garry Meax
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to write the contant of below array to a text file

and i use the following code to write

here is the contant of test.txt


why is it not writing the numbers (which is present in num_Survey[])


thanks

[ October 05, 2005: Message edited by: Garry Meax ]
[ October 05, 2005: Message edited by: Garry Meax ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is writing the numbers. There are five bytes in your file, one for each of the ints you write. But you don't want it to write the numbers -- you want it to write a textual representation of the numbers that you can read. The byte '1' doesn't correspond to the character "1" (which is actually the byte '49'!)

You want to do something like



Have a look at Sun's I/O tutorial to learn more about what's going on.
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way could be that you store your current "int" value into an Integer value.Like:
Integer num = new Integer(num_Survey[i]);

Thereof, you can easily use BufferedWriter to print it into any file.
 
Garry Meax
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Ernest for the quick reply. and thanks u too Anirvan.

Ernest, the code u gave,

it works but the thing is it writes those numbers vertically. i want to write them to file horizontally.

i thought i coud achieve it by changing println to print but it doesn't write anything when i changed


to

[ October 05, 2005: Message edited by: Garry Meax ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!