Last active
May 12, 2020 08:39
-
-
Save alvindizon/e15d4bf3a15d0b7f8cb2a5a7cacacc1c to your computer and use it in GitHub Desktop.
write text file to sdcard folder in android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Thread(() -> { | |
String errorPath = Environment.getExternalStorageDirectory().getPath() + | |
File.separator + Const.TEST_FILE_FOLDER; | |
File exceptionFolder = new File(errorPath); | |
if(!exceptionFolder.exists()) { | |
exceptionFolder.mkdir(); | |
} | |
File errFile = new File(errorPath + File.separator + Const.TEST_FILE); | |
if(!errFile.exists()) { | |
try { | |
errFile.createNewFile(); | |
} catch (IOException e) { | |
Toast.makeText(context, "Error creating test file", Toast.LENGTH_SHORT).show(); | |
return; | |
} | |
} | |
try (BufferedWriter bw = new BufferedWriter(new FileWriter(errFile, true))) { | |
bw.append(value); | |
bw.newLine(); | |
} catch (Exception e) { | |
Toast.makeText(context, "Error writing to file", Toast.LENGTH_SHORT).show(); | |
} | |
}).start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment