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

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

Reading a .pdb file

If you mean PDB as in a “program database” that the debugger uses: PDB files contain data about a file such as an EXE or DLL that is used to aid in debugging. There are public interfaces that allow you to extract data from the file. See examples here: https://learn.microsoft.com/en-us/archive/blogs/jmstall/sample-code-for-pdb-2-xml-tool (Moved from http://blogs.msdn.com/jmstall/archive/2005/08/25/pdb2xml.aspx) http://www.codeproject.com/KB/bugs/PdbParser.aspx If … Read more

How to download Postgres bytea column as file

One simple option is to use COPY command with encode to hex format and then apply xxd shell command (with -p continuous hexdump style switch). For example let’s say I have jpg image in bytea column in samples table: \copy (SELECT encode(file, ‘hex’) FROM samples LIMIT 1) TO ‘/home/grzegorz/Desktop/image.hex’ $ xxd -p -r image.hex > … Read more