• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to generate a text file? Please Help

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • 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.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • 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).]
 
Neelima Garimella
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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: 1869
  • Mark post as helpful
  • send pies
  • 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.
 
srival vas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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: 1869
  • Mark post as helpful
  • send pies
  • 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).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!