Hey I'm looking to run my java class and each time it is run it would print the console output to a new text file on the desktop. I know my syntax is a little weird with the methods but that's just how my mind works. I tried changing the output to a String variable so I could try to directly print it to the new text file however that didn't work. I removed all of my console to text code just for y'alls convenience. So basically my question is, when I run this, how would I print it to a new text file? (I apologize for any posting errors on my part as this is my first post on this site and I don't know the typical format) So I am editing this because I got downvoted because someone thought it was a replica question... I didn't state this but I know how to make a file through java but I want to make the output of a method be printed to a new text file, not just hard code it in. Sorry for the inconvenience.
public class Main {
public static void main(String[] args){
addHash();
}
public static void addHash() {
String outString = "#";
for (int maxRun = 0; maxRun <= 1000; maxRun++) {
for (int y = 0; y <= 10; y++) {
for (int x = -1; x <= y; x++) {
System.out.print(outString);
}
outString += "#";
System.out.println("");
}
for (int y = 10; y >= 0; y--) {
for (int x = 0; x <= y; x++) {
System.out.print(outString);
}
outString = outString.substring(0, outString.length() - 1);
System.out.println("");
}
}
}
}