I was searching a way to get System.out.println
texts and save them on a .txt file, for example:
System.out.println(\"Java vendor: \" + Syst
First you need to declare a String text
that contains your message you want to output:
String text = "Java vendor: " + System.getProperty("java.vendor");
Then you can use try-with-resources statement (since JDK 7) which will automatically close your PrintWriter
, when all the output done:
try(PrintWriter out = new PrintWriter("texts.txt") ){
out.println(text);
}