Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Writes Json/Gson to a temporary file and returns the Uri for the File
- *
- * @param context Application Context
- * @param any File Content
- * @param fileName Json File Name
- *
- * @return Uri for temp file with json
- * @throws FileNotFoundException Throws if json file cannot be found
- */
- @Throws(FileNotFoundException::class)
- internal fun writeJsonToFile(context: Context, jsonString: String, directoryName: String, fileName: String): Uri {
- val outputDir = File(context.filesDir, "$OUTPUT_PATH/$directoryName")
- if (!outputDir.exists()) {
- outputDir.mkdirs() // should succeed
- }
- val outputFile = File(outputDir, fileName)
- try {
- FileWriter(outputFile).use { it.write(jsonString) }
- } catch (e: Exception) {
- logStackTrace(e)
- }
- return Uri.fromFile(outputFile)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement