Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31887
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: basic output question |
| Date | 2015-06-30 09:05 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <mmu43k$tkm$1@dont-email.me> (permalink) |
| References | <635be647-55fb-43f9-8609-0320306ca853@googlegroups.com> <450dd941-b331-4f46-9e9c-e7db4033e0ca@googlegroups.com> |
On 6/30/2015 8:45 AM, e.d.programmer@gmail.com wrote:
> On Monday, June 29, 2015 at 2:40:05 PM UTC-4, Russ P. wrote:
>> Suppose I need a function (or method) for printing some (text-based) information to a file or to standard output. What is the recommended way to do this while minimizing duplication of code? Here's a simplification of what I came up with (in Scala, but using the Java standard library):
>>
>> def printInformation(out: java.io.PrintStream = System.out) {
>>
>> // print information here
>> }
>>
>> def printInformation(fileName: String) {
>> printInformation(new java.io.PrintStream(fileName))
>> }
>>
>> So if I call printInformation with no arguments, the output goes to standard output, but if I give it a filename the output goes to the file. Is this the best way to do it, or is there a simpler/better way? I'd also like to be able to append the output to an existing file as well as create a new file. Thanks.
>
> I never quite got the logging frameworks ie commons logging.
s/ie/eg/
> You have to deal with someone else's API, [...]
That's called "component reuse," and most people think of it
as a Good Thing. In moderation, of course.
> [...] set warning levels, and include an extra jar in the classpath. [...]
There's also the built-in java.util.logging package, assuming you're
using a post-2002 Java version.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
basic output question "Russ P." <russ.paielli@gmail.com> - 2015-06-29 11:39 -0700
Re: basic output question Arne Vajhøj <arne@vajhoej.dk> - 2015-06-29 14:53 -0400
Re: basic output question Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-06-29 15:32 -0400
Re: basic output question e.d.programmer@gmail.com - 2015-06-30 05:45 -0700
Re: basic output question Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-06-30 09:05 -0400
Re: basic output question e.d.programmer@gmail.com - 2015-06-30 11:28 -0700
Re: basic output question Arne Vajhøj <arne@vajhoej.dk> - 2015-06-30 14:55 -0400
Re: basic output question e.d.programmer@gmail.com - 2015-06-30 12:14 -0700
Re: basic output question Arne Vajhøj <arne@vajhoej.dk> - 2015-07-27 22:25 -0400
Re: basic output question Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-06-30 15:27 -0400
csiph-web