samedi 31 octobre 2015

How to create many files (with different names) in a specifc directory?

The goal is to every time a person gives a name on a TextField, I can create a file with that name + "messageLog.txt". And these creations are send to specific folder.

What I have now is:

String ficheiro = localDoNome.getText() + "_messageLo.txt");
PrintWriter writer = new PrintWriter(ficheiro);
writer.close();

This allows me to create files with the desired names, but have yet to enter the directory I want. I know the following code allows me to write a file in directory I want.

PrintWriter writer = new PrintWriter("confdir/ficheiro.txt");

The problem is, I can't see a way to combine this two codes. Because if I do

PrintWriter writer = new PrintWriter ("confdir / ficheiro");

It's gonna always create a file named ficheiro. And what I want is to create in that directory "confdir" files like banana.messageLo.txt, laranja.messageLo.txt, etc....

Aucun commentaire:

Enregistrer un commentaire