Questions tagged [printstream]
175 questions
7
votes
9 answers
On system.out, clarification needed
I was looking at someone's code and saw that he repeatedly declared
PrintStream out = System.out;
and later called
out.println("blah");
I actually thought this was kind of neat. Is this a common practice? Was he just being fancy?

James Raitsev
- 92,517
- 154
- 335
- 470
5
votes
4 answers
Writing a formatted string to a file - Java
I have a string that I format with the System.out.format() method, I do something like :
System.out.format("I = %3d var = %9.6f", i, myVar);
but when I try to write this formatted string into a file, I only get something like…

T.Durand
- 77
- 2
- 11
5
votes
1 answer
In PrintWriter, why doesn't the print() function also auto-flush?
When looking at the PrintWriter contract for the following constructor:
public PrintWriter(OutputStream out, boolean autoFlush)
Creates a new PrintWriter from an existing OutputStream. This convenience constructor creates the necessary…

E.S.
- 2,733
- 6
- 36
- 71
5
votes
2 answers
Java: Why don't the PrintWriter or PrintStream classes throw exception?
Possible Duplicate:
PrintWriter and PrintStream never throw IOExceptions
Maybe the question is a bit "strange". But i'm curious to know why both PrintWriter and PrintStream don't check automatically runtime exceptions , and they provides a…
user1462183
3
votes
1 answer
Changing Locale of a printstream in Java
I'm working on a project in which you can draw lines on a canvas and save it in a textfile with coordinates for each line.
However, when I try to save it with this method, and write it to the textfile, all dots are replaced by commas.
I assume this…

ConradDoggo
- 91
- 8
3
votes
1 answer
Thread Safety of PrintStream in Java
I am trying to write to a file. I need to be able to "append" to the file rather than write over it. Also, I need it to be thread safe and efficient. The code I have currently is:
private void writeToFile(String data) {
File file = new…

Nick Humrich
- 14,905
- 8
- 62
- 85
2
votes
1 answer
Append to text file using PrintStream
I cant append text to a text file, it only overwrites the previous text. My code:
//using JFileChooser to select where to save file
PrintStream outputStream = MyFrame.ShowSaveDialog();
if(outputStream!=null){
outputStream.append(input);
…

Twistar
- 782
- 5
- 21
- 35
2
votes
2 answers
PrintStream doesn't print
in = new BufferedReader (new InputStreamReader(client.getInputStream()));
out = new DataOutputStream(client.getOutputStream());
ps = new PrintStream(out);
public void run() {
String line;
try {
while ((line = in.readLine()) !=…

Rona
- 25
- 1
- 2
- 6
2
votes
3 answers
UTF-8 encoding for output from Console to JavaFX TextArea
I want to redirect the output in Console to JavaFX TextArea, and I follow a suggestion here: JavaFX: Redirect console output to TextArea that is created in SceneBuilder
I tried to set charset to UTF-8 in PrintStream(), but it does not look so well.…

Ha Trung Nam Hai
- 23
- 5
2
votes
3 answers
Java - How to use PrintStream/OutputStream to print to the Command Line
I know we can use PrintStream to print lines to a given file:
PrintStream output;
output = new PrintStream("./temp.txt");
output .println("some output text");
However, can we use PrintStream to print lines to the command line?
I've…

user3211306
- 388
- 1
- 4
- 12
2
votes
3 answers
Why does PrintStream::printf return a PrintStream?
PrintStream's printf method has a return type of PrintStream and every time it is called it returns this object (the other print methods are void). So why is it designed like this? And for that matter if you have an object of any type that has a…

Chris Tzikas
- 41
- 6
2
votes
0 answers
Why doesn't System.out return a null object?
In System.java, out is instantiated by:
public final static PrintStream out = nullPrintStream();
You would expect this to return a valid PrintStream object, except this is what the method looks like:
private static PrintStream nullPrintStream()…

Dan
- 474
- 1
- 7
- 16
2
votes
0 answers
Extra linefeeds around PrintStream.printf() arguments in a server app
In a plain Java application, this code:
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("java.vendor"));
System.out.printf("XXXX %s YYY\n","Something");
System.out.printf("XXXX %s…

xenoid
- 8,396
- 3
- 23
- 49
2
votes
2 answers
System.out.print output to console seen immediately. So PrintStream flushes after each print, not only println?
From the PrintStream documentation:
Optionally, a PrintStream can be created so as to flush automatically;
this means that the flush method is automatically invoked after a byte
array is written, one of the println methods is invoked, or a…

LrnBoy
- 373
- 1
- 2
- 9
2
votes
2 answers
printStackTrace vs Logger Frameworks in Java
In Java, exception handling can be done in multiple ways. Let's differentiate exception handling using Logging framework as log4j or sl4j, where both of these could either redirect the logs to a file in addition to handle the exception.
If, instead…

Akhil Gupta
- 265
- 1
- 14