try this one
public void writeFile(String arg1,String arg2) {_x000D_
try {_x000D_
if (!dir.exists()) {_x000D_
_x000D_
if (dir.mkdirs()) {_x000D_
_x000D_
Toast.makeText(getBaseContext(), "Directory created",_x000D_
Toast.LENGTH_SHORT).show();_x000D_
} else {_x000D_
Toast.makeText(getBaseContext(),_x000D_
"Error writng file " + filename, Toast.LENGTH_LONG)_x000D_
.show();_x000D_
}_x000D_
}_x000D_
_x000D_
else {_x000D_
_x000D_
File file = new File(dir, filename);_x000D_
if (!file.exists()) {_x000D_
file.createNewFile();_x000D_
}_x000D_
_x000D_
FileWriter fileWritter = new FileWriter(file, true);_x000D_
BufferedWriter bufferWritter = new BufferedWriter(fileWritter);_x000D_
bufferWritter.write(arg1 + "\n");_x000D_
bufferWritter.close();_x000D_
_x000D_
} catch (Exception e) {_x000D_
e.printStackTrace();_x000D_
Toast.makeText(getBaseContext(),_x000D_
"Error writng file " + e.toString(), Toast.LENGTH_LONG)_x000D_
.show();_x000D_
}_x000D_
_x000D_
}
_x000D_