How to name a text file with Edittext information?

Asked

Viewed 82 times

0

In my registration app I have the name and phone information. After entering the information and clicking register, a text file is created with the registered information.

But I would like the created text file to be named with the name field information.

Example:

Name: Joao
Telephone: 123

Text file created: Joao.txt

Currently, I create and name the file with the following command:

FileOutputStream ArqTexto = new FileOutputStream(Environment.getExternalStorageDirectory() + "/Clientes.txt");

I have already stored the value inserted in the name field in a variable, but I don’t know how to make the correct syntax.

I tried so:

FileOutputStream ArqTexto = new FileOutputStream(Environment.getExternalStorageDirectory() + VariavelNome +".txt");

But it didn’t work.

  • 1

    We missed a / between the directory and its VariavelNome.

  • Great @Paulorodrigues thank you so much! That’s right!

  • It is interesting also you remove possible special characters when give names to these files, because in some cases your application can give a force close.

1 answer

0


The correct is:

FileOutputStream ArqTexto = new FileOutputStream(Environment.getExternalStorageDirectory() +"/"+ VariavelNome +".txt");

The bar was missing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.