Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing to a .txt file  RSS feed

 
indi bose
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
Can anyone please let me know, how to write to a .txt file taking the input from the console ?Also i need to write to the same file over and over again the inputs and everytime I want to keep adding to the original contents instead of overwriting it.

Thanks in advance
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To read from standard in, take a look at the System.in variable. (Actually, take a look at the java.lang.System and java.io.InputStream class in JavaDocs for more info)

To write to a file, take a look at java.io.FileOutputStream or java.io.FileWriter classes. (again, in JavaDocs) The "append" mode is available from the contructors.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!