0

as the title said i want to show the console log to the user of my application

I come with this

package utility;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import javafx.scene.control.TextArea;

public class Log {

public static void checkLog(TextArea txt) throws IOException {

    Console console = new Console(txt);
    PrintStream ps = new PrintStream(console, true);
    System.setOut(ps);
    System.setErr(ps);

    for (char c : "some text".toCharArray()) {
        console.write(c);
    }
    ps.close();
}

public static class Console extends OutputStream {

    private TextArea output;

    public Console(TextArea ta) {
        this.output = ta;
    }

    @Override
    public void write(int i) throws IOException {
        output.appendText(String.valueOf((char) i));
    }
}
}

And i put the thing in

TextArea txt = new TextArea();
Log.checkLog(txt);
Scene scene = new Scene(txt, 700, 500);

when i clic on my button to show my stage with my TextArea in it ... the only thing that i see is : "some text" without quote ...

But what i want is all my System.out.print

Did i miss something ?

Thanks for your answer ...

V.Cullard
  • 19
  • 1
  • 6
  • 1
    Possible duplicate of [How can I make Java print quotes, like "Hello"?](http://stackoverflow.com/questions/3844595/how-can-i-make-java-print-quotes-like-hello); also [How to enter quotes in a Java string?](http://stackoverflow.com/questions/3559063/how-to-enter-quotes-in-a-java-string) – fabian May 27 '16 at 14:08
  • So show me where is your duplicate question maybe ? @James_D So there is no duplicate ... can someone answer me ... See my edit maybe you don't understand my question Thanks – V.Cullard May 27 '16 at 15:12
  • Could someone remove the [duplicate] flag plz ... Just look my title "Print Console in Application JavaFX" it's not like "How can I make Java print quotes, like “Hello”? " – V.Cullard May 27 '16 at 15:17
  • Why block my question when it's not a duplicate ? @fabian ? – V.Cullard May 27 '16 at 15:22
  • The part about redirecting `System.out` to a `TextArea` has been asked somewhere too. I voted for close in the first place, since you're asking why characters that aren't even in the string are not written to the stream, which IMHO is sufficiently similar to the dupe. – fabian May 27 '16 at 15:31
  • Totally unclear what you're asking then. What are you trying to do? You need to [edit] the question to make it clearer what you mean. The code you posted will clearly just display the text *some text* in the text area; if you want something different to that, you need to explain what you want and post code that shows an attempt to do it. – James_D May 27 '16 at 18:55
  • more clear than that : "But what i want is all my System.out.print" ? ... thanks anyway .. – V.Cullard May 28 '16 at 11:53
  • You just don't read my post until the end, nevermind, i don't understand this treatment. – V.Cullard May 30 '16 at 07:56
  • So now how to get help for that problem ? You locked it ... and if i start a new one i'm afraid someone block it too... Did i should post my question in a nearly similar subject ? I don't understand this kind of treatement, i read the FAQ and my question was clear enough ... So should i start a new Question ? or add a comment in a similiar question ? – V.Cullard Jun 01 '16 at 15:55

0 Answers0