Create Text File Without BOM

Well it writes the BOM because you are instructing it to, in the line Encoding utf8WithoutBom = new UTF8Encoding(true); true means that the BOM should be emitted, using Encoding utf8WithoutBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); writes no BOM. My objective is create a file using UTF-8 as Encoding and 8859-1 as CharSet Sadly, this is not … Read more

Convert tab-delimited txt file into a csv file using Python

csv supports tab delimited files. Supply the delimiter argument to reader: import csv txt_file = r”mytxt.txt” csv_file = r”mycsv.csv” # use ‘with’ if the program isn’t going to immediately terminate # so you don’t leave files open # the ‘b’ is necessary on Windows # it prevents \x1a, Ctrl-z, from ending the stream prematurely # … Read more

Java BufferedReader back to the top of a text file?

The Buffered readers are meant to read a file sequentially. What you are looking for is the java.io.RandomAccessFile, and then you can use seek() to take you to where you want in the file. The random access reader is implemented like so: try{ String fileName = “c:/myraffile.txt”; File file = new File(fileName); RandomAccessFile raf = … Read more

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

How do you extract email addresses from the ‘To’ field in outlook?

Check out the Recipients collection object for your mail item, which should allow you to get the address: http://msdn.microsoft.com/en-us/library/office/ff868695.aspx Update 8/10/2017 Looking back on this answer, I realized I did a bad thing by only linking somewhere and not providing a bit more info. Here’s a code snippet from that MSDN link above, showing how … Read more

Open a text file in the default text editor… via Java?

You can do that with: java.awt.Desktop.getDesktop().edit(file); This links to the tutorial article on java.awt.Desktop: Java™ Standard Edition version 6 narrows the gap between performance and integration of native applications and Java applications. Along with the new system tray functionality, splash screen support, and enhanced printing for JTables , Java SE version 6 provides the Desktop … Read more

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