text-files

Write mutiple lines to a text file using Visual Basic

自作多情 提交于 2019-12-21 06:02:03
问题 I'm trying to check to see if a file exists, if so it does nothing. If the file does not exist is creates the text file. Then I want to write text to that file. Where am I going wrong with this code? I'm just trying to write multiple lines to the text file and that part is not working. It is creating the text file... just not writing to it. Dim file As System.IO.FileStream Try ' Indicate whether the text file exists If My.Computer.FileSystem.FileExists("c:\directory\textfile.txt") Then Return

Fastest/Cleanest way to load a text file in memory

南楼画角 提交于 2019-12-21 04:05:16
问题 I know similar questions have been asked before, but I couldn't find one that answers my exact question. I need a way to read a file as a String with the least code and as simple and as optimal as possible. I'm not looking for: final BufferedReader br = new BufferedReader(new FileReader(file)); String line = null; while ((line = br.readLine()) != null) { // logic } And I know I can write my own helper class that does this. I'm looking for something more along the lines of: final String

Determine what line ending is used in a text file

百般思念 提交于 2019-12-21 04:04:36
问题 Whats the best way in C# to determine the line endings used in a text file (Unix, Windows, Mac)? 回答1: Notice that text files may have inconsistent line endings. Your program should not choke on that. Using ReadLine on a StreamReader (and similar methods) will take care of any possible line ending automatically. If you manually read lines from a file, make sure to accept any line endings, even if inconsistent. In practice, this is quite easy using the following algorithm: Scan ahead until you

How to convert a tab separated file to CSV format?

瘦欲@ 提交于 2019-12-21 03:19:26
问题 I have a text file in this format : { attribute1 attribute2 attribute3.... attributeN value"A" value"B" value"C".... value"Z" /* next line of values*/ } Each word is separated by a tab. How do I convert to CSV format? I tried using Excel but it's giving compatibility issues. 回答1: Import the data with excel (Data > Load from text file), using tab as a column separator. Then save the file as csv. It cannot have compatibility issues, it's a basic task and i did it quite often in the past. 回答2:

How do I read information from text files?

北战南征 提交于 2019-12-20 14:23:35
问题 I have hundreds of text files with the following information in each file: *****Auto-Corelation Results****** 1 .09 -.19 .18 non-Significant *****STATISTICS FOR MANN-KENDELL TEST****** S= 609 VAR(S)= 162409.70 Z= 1.51 Random : No trend at 95% *****SENs STATISTICS ****** SEN SLOPE = .24 Now, I want to read all these files, and "collect" Sen's Statistics from each file (eg. .24 ) and compile into one file along with the corresponding file names. I have to do it in R. I have worked with CSV

Proper Java classes for reading and writing files?

心不动则不痛 提交于 2019-12-20 10:43:28
问题 Reading some sources about Java file I/O managing, I get to know that there are more than 1 alternative for input and output operations. These are: BufferedReader and BufferedWriter FileReader and FileWriter FileInputStream and FileOutputStream InputStreamReader and OutputStreamWriter Scanner class What of these is best alternative for text files managing? What's best alternative for serialization? What does Java NIO say about it? 回答1: Two kinds of data Generally speaking there are two

How do I pair every two lines of a text file with Bash? [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-20 10:18:25
问题 This question already has answers here : How to merge every two lines into one from the command line? (20 answers) Closed 3 years ago . With a simple bash script I generate a text file with many lines like this: 192.168.1.1 hostname1 192.168.1.2 hostname2 192.168.1.3 hostname3 Now I want to reformat this file so it looks like this: 192.168.1.1 hostname1 192.168.1.2 hostname2 192.168.1.3 hostname3 How would I reformat it this way? Perhaps sed ? 回答1: $ sed '$!N;s/\n/ /' infile 192.168.1.1

Adding only specific text from a file to an array list, part 2 - Java

陌路散爱 提交于 2019-12-20 07:39:50
问题 I hope I can have some great suggestion how I can solve this here: I have this text file with places and names - name detail indicates the place(s) that the person has visited: Place: New York Place: London Place: Paris Place: Hongkong 1. Name: John 1. Name detail: London 1. Name detail: Paris 1. Name detail: Hongkong 2. Name: Sarah 2. Name detail: London 3. Name: David 3. Name detail: New York 3. Name detail: Paris Here is a part of my code. private ArrayList<Place> places = new ArrayList<>(

read from a text file and load it into a matrix in matlab [duplicate]

你离开我真会死。 提交于 2019-12-20 07:34:28
问题 This question already has answers here : Matlab read in txt file into array (2 answers) Closed 6 years ago . I have a text file called coordinates.txt as following format: 0 0 0 -0.95 0.32 -0.02 -1.02 0.26 -0.96 -0.73 0.6 -0.52 -0.77 0.6 -0.71 -0.28 0 -0.95 -0.14 -0.16 0.13 -0.46 -1 -0.29 -1.14 -0.6 0.16 How could I load it in matlab with commands and save it in a matrix called X as following: X=[0 0 0; -0.95 0.32 -0.02; -1.02 0.26 -0.96; -0.73 0.6 -0.52; -0.77 0.6 -0.71; -0.28 0 -0.95; -0.14

C# StreamReader save to Array with separator

て烟熏妆下的殇ゞ 提交于 2019-12-20 07:19:13
问题 I´ve got a text file with tabulator separated data. What I need in my C# application is that I read one line from the text file and save them to an array, separate them at the each \t . Then I do the same thing with the next row. My code: StreamReader sr = new StreamReader(dlg.FileName); string s = sr.ReadLine(); Now, I already tried to write the line into an array but that doesn´t work. Does anyone one how to manage this? 回答1: Use the Split method to create an Array of the line string[]