• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

writing to a text file from cmmand prompt

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic