text-files

Historical reason behind different line ending at different platforms

谁说我不能喝 提交于 2019-11-27 04:35:55
Why did DOS/Windows and Mac decide to use \r\n and \r for line ending instead of \n? Was it just a result of trying to be "different" from Unix? And now that Mac OS X is Unix (-like), did Apple switch to \n from \r? 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 move to the next line (LF = line feed). The

Get the number of lines in a text file using R

a 夏天 提交于 2019-11-27 04:30:09
问题 Is there a way to get the number of lines in a file without importing it? So far this is what I am doing myfiles <- list.files(pattern="*.dat") myfilesContent <- lapply(myfiles, read.delim, header=F, quote="\"") for (i in 1:length(myfiles)){ test[[i]] <- length(myfilesContent[[i]]$V1) } but is too time consuming since each file is quite big. 回答1: If you: still want to avoid the system call that a system2("wc"… will cause are on BSD/Linux or OS X (I didn't test the following on Windows) don't

Create Text File Without BOM

心已入冬 提交于 2019-11-27 04:03:52
问题 I tried this aproach without any success the code I'm using: // File name String filename = String.Format("{0:ddMMyyHHmm}", dtFileCreated); String filePath = Path.Combine(Server.MapPath("App_Data"), filename + ".txt"); // Process myObject pbs = new myObject(); pbs.GenerateFile(); // pbs.GeneratedFile is a StringBuilder object // Save file Encoding utf8WithoutBom = new UTF8Encoding(true); TextWriter tw = new StreamWriter(filePath, false, utf8WithoutBom); foreach (string s in pbs.GeneratedFile

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

冷暖自知 提交于 2019-11-27 03:59:19
So I want to convert a simple tab delimited text file into a csv file. If I convert the txt file into a string using string.split('\n') I get a list with each list item as a string with '\t' between each column. I was thinking I could just replace the '\t' with a comma but it won't treat the string within the list like string and allow me to use string.replace. Here is start of my code that still needs a way to parse the tab "\t". import csv import sys txt_file = r"mytxt.txt" csv_file = r"mycsv.csv" in_txt = open(txt_file, "r") out_csv = csv.writer(open(csv_file, 'wb')) file_string = in_txt

Simplest way to encrypt a text file in java

扶醉桌前 提交于 2019-11-27 03:40:55
For my School project I had to show that I can utilize file handling within a program. For this I made a very simple login process that you can create an account on that writes a username and password to a text file located in the resource folder. Obviously this has no security at all as it wasn't designed to be secure just to showcase file handling however my teacher has said that I should attempt to add some encryption to the file as well to get a better grade. I have done some research and many people are recommending DES. The problem I'm having is I don't have much time left for my project

How do I read and edit a .txt file in C#?

﹥>﹥吖頭↗ 提交于 2019-11-27 03:26:47
问题 For example, I have a txt file that reads: 12 345 45 2342 234 45 2 2 45345 234 546 34 3 45 65 765 12 23 434 34 56 76 5 I want to insert a comma between all the numbers, add a left brace to the begining of each line and a right brace to the end of each line. So after the editing it should read: {12, 345, 45} {2342, 234, 45, 2, 2, 45345} {234, 546, 34, 3, 45, 65, 765} {12, 23, 434, 34, 56, 76, 5} How do I do it? 回答1: Added some LINQ for fun and profit (room for optimization ;) ): System.IO.File

c++: ifstream open problem with passing a string for text file name [duplicate]

蓝咒 提交于 2019-11-27 03:18:12
问题 This question already has an answer here: No matching function - ifstream open() 1 answer i'm trying to pass a string from main to another function. this string is a name of text file that needs to be oepened. as far as i can see, i am passing the string alright, but when i try to use ifstream.open(textFileName) , it doesn't quite work. but when i manually hardcode it as ifstream.open("foo.txt") , it works just fine. i would need to use this function several times so i would like to be able

Fetching zipped text file and unzipping in client browsers, feasible in Javascript?

好久不见. 提交于 2019-11-27 01:55:20
问题 I am developing a web page containing Javascript. This js uses static string data (about 1-2 MB) which is stored in a flat file. I could compress it with gzip or any other algorithm to reduce the transfer load. Would it be possible to fetch this binary file with Ajax and decompress it into a string (which I could split later) in the client browser. If yes, how can I achieve this? Does anyone have a code example? 回答1: And another library or site is this one, although it has few examples it has

How do I split a huge text file in python

安稳与你 提交于 2019-11-27 01:48:18
问题 I have a huge text file (~1GB) and sadly the text editor I use won't read such a large file. However, if I can just split it into two or three parts I'll be fine, so, as an exercise I wanted to write a program in python to do it. What I think I want the program to do is to find the size of a file, divide that number into parts, and for each part, read up to that point in chunks, writing to a filename .nnn output file, then read up-to the next line-break and write that, then close the output

How to add new line into txt file

折月煮酒 提交于 2019-11-27 00:23:59
I'd like to add new line with text to my date.txt file, but instead of adding it into existing date.txt, app is creating new date.txt file.. TextWriter tw = new StreamWriter("date.txt"); // write a line of text to the file tw.WriteLine(DateTime.Now); // close the stream tw.Close(); I'd like to open txt file, add some text, close it, and later after clicking something: open date.txt, add text, and close it again. So i can get: Button pressed: txt opened -> added current time, then close it. Another button pressed, txt opened -> added text "OK", or "NOT OK" in the same line, then close it again.