Search code examples
androidstringfilenamesfilewriter

Use string as a filename


I need a help. I have an android app. I am using editText to get string. Then I create a file something.txt and write data in it. How Can I set file name to mystring.txt ?

try {
        writer = new FileWriter(root + "/filename.txt",true);
    } catch (IOException e) {
        e.printStackTrace();
    }

I need it cause I need to have all data with different filename for my app... Thanks


Solution

  • You would have to use

    String desiredFileName = edittext.getText().toString();
    try {
        writer = new FileWriter(root + "/" + desiredFileName + ".txt",true);
    } catch (IOException e) {
        e.printStackTrace();
    }