• 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

How to generate a text file? Please Help

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application in which some text (that includes int and double values) to certain file. How can I view a text file.
I tried with RandomAccessFile by writing the text and numbers using WriteInt and WriteDouble methods etc. But when I tried to view the text file..it displays all the junk with some characters as *...and etc. Can any one please help me..
Neelima.
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using the FileOutputStreams or the FileWriter class. An example of the FileOutputStream is given below.

The RandomAccessFile methods too work but you may have to use the correct methods like this


[This message has been edited by Rahul Mahindrakar (edited October 02, 2000).]
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Rahul,
I tried using FileOutputStream and RandomAccessFile as you have specified. I also tried the examples that you have given. But, it gives a compile time error as "Invalied character Constant", at the place of single quote. i.e., at the place of write('10').
Neelima
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neelima ,
the Write method is overloaded in many ways. Please check up the documentation for this. it takes a char, a char array etc..But it does not take a string. Please note that '10' is not a valid character but '1' and '0' are.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
continuing on this topic, how would I write a newline character
to a text file,
a character like 's', I can cast off to int and proceed but
I am stuck at a newline character.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hope the code below will clarify things for you adequately

[This message has been edited by Rahul Mahindrakar (edited October 15, 2000).]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic