i tried the code below!!every time it replaces contents from file “textfile.txt” i want the user to add files to SD card with name which they have entered as “filename”
i have registered onclick listener on save button
Code:
EditText filename =(EditText) findViewById(R.id.filename);
EditText filecontent =(EditText) findViewById(R.id.filecontent);
public void onClick(View view)
{
String str = filename.getText().toString();
String str2= filecontent.getText().toString();
file sdCard = Environment.getExternalStorageDirectory();
File directory = new File (sdCard.getAbsolutePath() +"/MyFiles");
directory.mkdirs();
File file = new File(directory,"textfile.txt");
file.createNewFile();
FileOutputStream fOut = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write(str);
osw.write(" ");
osw.write(str2);
osw.flush();
osw.close();
}
change it to
File file = new File(directory,str+”.txt”);
it will store file S THE NAME GIVEN BY USER!!!