How to read plain text file in kotlin?

1. Using BufferedReader import java.io.File import java.io.BufferedReader fun main(args: Array<String>) { val bufferedReader: BufferedReader = File(“example.txt”).bufferedReader() val inputString = bufferedReader.use { it.readText() } println(inputString) } 2. Using InputStream Read By Line import java.io.File import java.io.InputStream fun main(args: Array<String>) { val inputStream: InputStream = File(“example.txt”).inputStream() val lineList = mutableListOf<String>() inputStream.bufferedReader().forEachLine { lineList.add(it) } lineList.forEach{println(“> ” + … Read more

Difference between io.open vs open in python

Situation in Python3 according to the docs: io.open(file, *[options]*) This is an alias for the builtin open() function. and While the builtin open() and the associated io module are the recommended approach for working with encoded text files, this module [i.e. codecs] provides additional utility functions and classes that allow the use of a wider … Read more

Download file from url, save to phones storage

Use https://pub.dartlang.org/packages/flutter_downloader. Don’t forget to do platform configurations. Basically, this is how you should use the package. There is a detailed long example in the link. final taskId = await FlutterDownloader.enqueue( url: ‘your download link’, savedDir: ‘the path of directory where you want to save downloaded files’, showNotification: true, // show download progress in status … Read more

Request.Files in ASP.NET CORE

This is working code from a recent project. Data has been moved from Request.Files to Request.Form.Files. In case you need to convert stream to byte array – this is the only implementation that worked for me. Others would return empty array. using System.IO; var filePath = Path.GetTempFileName(); foreach (var formFile in Request.Form.Files) { if (formFile.Length … Read more