• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to write console output to a .txt file  RSS feed

 
Brett Banich
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


How can I save "encoded" to a .txt file defined with the input file name + " - ciphered" appended to it. I've tried this but not really sure how to use this or if this is correct:
 
Rocky Rocha
Ranch Hand
Posts: 59
Android Chrome Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should use
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the API documentation for PrintStream and you'll find it has all kinds of methods for writing all kinds of things to the PrintStream. You've got a String which you want to write, so find the method which does that. Don't forget to close the PrintStream when you're finished writing to it!
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can write text with the opposite of a Scanner, viz. a Formatter. You can pass a File to its constructor with Paths.get(...)toFile(), and use its format() method to write to the file. Probably the best way to close the Formatter is to use try with resources.Note: Scanners and Formatters are only any good for text files; they are not suitable for handling encoded byte[]s which are binary data.

Does the use of the toFile method mean that they have forgotten to upgrade Formatter by not giving its a constructor taking a Path as a parameter?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!