How to Create a file based off of a variable JAVA

Hey guys I have a PrintWriter object and I want to create a file with a variable instead of entering a String.

PrintWriter out1= new PrintWriter(name.getName())//how would I make that name that it gets into the name of the text file?

The name of a file has to be a string of some sort. So, if name.getName() returns a variable of type String, you're code should be fine.

Otherwise you'll need a "ToString" method, that will turn whatever name.getName() returns into a string and give it to you (eg some method in your name class that can be invoked as name.getNameAsString()). Many primitive types have a ToString() you can use.

Does it need a file extension?

Yes, sorry. It does, so you'll have to concatenate, like so:

PrintWriter out1= new PrintWriter(name.getName() + ".txt"); (substituting whatever method gets you that String if name.getName() doesn't).