samedi 31 octobre 2015

How Can I create a file (the name can change) in a specific directory?

I want to create different files (ended with .txt but with different names(depends on what I put in the textfield "localDoNome") into a specific directory.

What I have now is:

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

This code works fine for creating different files. Miss the part "to a specific directory".

I know that I can do something like:

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

The problem with this last code is that is all String, this means the initial "ficheiro" would be all String too, which leads to not creating different files.

Aucun commentaire:

Enregistrer un commentaire