Historical reason behind different line ending at different platforms

DOS inherited CR-LF line endings (what you’re calling \r\n, just making the ascii characters explicit) from CP/M. CP/M inherited it from the various DEC operating systems which influenced CP/M designer Gary Kildall. CR-LF was used so that the teletype machines would return the print head to the left margin (CR = carriage return), and then … Read more

How to read and write a text file in Flutter

Setup Add the following plugin in pubspec.yaml: dependencies: path_provider: ^1.6.27 Update the version number to whatever is current. And import it in your code. import ‘package:path_provider/path_provider.dart’; You also have to import dart:io to use the File class. import ‘dart:io’; Writing to a text file _write(String text) async { final Directory directory = await getApplicationDocumentsDirectory(); final … Read more

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

Python Multiple users append to the same file at the same time

You can use file locking: import fcntl new_entry = “foobar” with open(“/somepath/somefile.txt”, “a”) as g: fcntl.flock(g, fcntl.LOCK_EX) g.write(new_entry) fcntl.flock(g, fcntl.LOCK_UN) Note that on some systems, locking is not needed if you’re only writing small buffers, because appends on these systems are atomic.

Copying from one text file to another using Python

The oneliner: open(“out1.txt”, “w”).writelines([l for l in open(“in.txt”).readlines() if “tests/file/myword” in l]) Recommended with with: with open(“in.txt”) as f: lines = f.readlines() lines = [l for l in lines if “ROW” in l] with open(“out.txt”, “w”) as f1: f1.writelines(lines) Using less memory: with open(“in.txt”) as f: with open(“out.txt”, “w”) as f1: for line in f: … Read more

remove empty lines from text file with PowerShell

I found a nice one liner here >> http://www.pixelchef.net/remove-empty-lines-file-powershell. Just tested it out with several blanks lines including newlines only as well as lines with just spaces, just tabs, and combinations. (gc file.txt) | ? {$_.trim() -ne “” } | set-content file.txt See the original for some notes about the code. Nice 🙂

How to read text file in react

Simply try the below code and you may understand import React, { Component } from ‘react’; class App extends Component { constructor(props) { super(props); } showFile = async (e) => { e.preventDefault() const reader = new FileReader() reader.onload = async (e) => { const text = (e.target.result) console.log(text) alert(text) }; reader.readAsText(e.target.files[0]) } render = () … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)