text-files

How to save a structure array to a text file

穿精又带淫゛_ 提交于 2019-11-29 07:42:48
In MATLAB how do I save a structure array to a text file so that it displays everything the structure array shows in the command window? You have to define a format for your file first. Saving to a MATLAB workspace file (.MAT) If you don't care about the format, and simply want to be able to load the data at a later time, use save , for example: save 'myfile.mat' structarr That stores struct array structarr in a binary MAT file named "file.mat". To read it back into your workspace you can use load : load 'myfile.mat' Saving as comma-separated values (.CSV) If you want to save your struct array

Read txt file in Matlab

陌路散爱 提交于 2019-11-29 07:02:25
I have a trouble reading the txt file, which contains 10 columns and 2 lines of header, but the problem is that in the middle of the file the same header appears several times and textread() doesnt function. That's my file example: file.txt headerline1 aaaa headerline2 111 123 20/12/2000 name1 name2 name3... name8 0 21/12/2000 name1 name2 name3... name8 0 22/12/2000 name1 name2 name3... name8 0 headerline1 aaaa headerline2 111 123 25/12/2000 name1 name2 name3... name8 0 27/12/2000 name1 name2 name3... name8 0 ... and this is my code I tried: [date, name1, name2, name3, name4, name5, name6,

Quickest way to read text-file line by line in Java

北战南征 提交于 2019-11-29 07:01:33
For log processing my application needs to read text files line by line. First I used the function readLine() of BufferedReader but I read on the internet that BufferedReader is slow when reading files. Afterwards I tried to use FileInputStream together with a FileChannel and MappedByteBuffer but in this case there's no function similar to readLine() so I search my text for a line-break and process it: try { FileInputStream f = new FileInputStream(file); FileChannel ch = f.getChannel( ); MappedByteBuffer mb = ch.map(FileChannel.MapMode.READ_ONLY, 0L, ch.size()); byte[] bytes = new byte[1024];

C# Read Text File Containing Data Delimited By Tabs

假如想象 提交于 2019-11-29 06:21:46
I have some code: public static void ReadTextFile() { string line; // Read the file and display it line by line. using (StreamReader file = new StreamReader(@"C:\Documents and Settings\Administrator\Desktop\snpprivatesellerlist.txt")) { while ((line = file.ReadLine()) != null) { char[] delimiters = new char[] { '\t' }; string[] parts = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < parts.Length; i++) { Console.WriteLine(parts[i]); sepList.Add(parts[i]); } } file.Close(); } // Suspend the screen. Console.ReadLine(); } It reads in a text file that contains

Java Text File Encoding

我与影子孤独终老i 提交于 2019-11-29 06:13:32
I have a text file and it can be ANSI (with ISO-8859-2 charset), UTF-8, UCS-2 Big or Little Endian. Is there any way to detect the encoding of the file to read it properly? Or is it possible to read a file without giving the encoding? (and it reads the file as it is) (There are several program that can detect and convert encoding/format of text files.) UTF-8 and UCS-2/UTF-16 can be distinguished reasonably easily via a byte order mark at the start of the file. If this exists then it's a pretty good bet that the file is in that encoding - but it's not a dead certainty. You may well also find

What is the best way to read in a text file from the server in asp.net-mvc

亡梦爱人 提交于 2019-11-29 04:26:23
问题 In one of my controller actions I need to read in a text file that has a bunch of reference data in it. Right now I simply put it in the "/Content" directory. My questions are: Is this the "right" place to put this file or should I put it in another directory? What is the best way to read in a text file in asp.net-mvc that is sitting on the server? 回答1: If the file should not be directly available via URL, you should put it in App_Data. For reading it, just use: var fileContents = System.IO

Writing TXT File with PHP, Want to Add an Actual Line Break

五迷三道 提交于 2019-11-29 03:23:37
I am writing a TXT file using PHP. I want to insert actual line breaks into the TXT file wherever necessary. I have tried all combinations of \n \r \r\n \n\r ... but these are not causing any linebreaks to appear - in most cases, I am seeing the text "\n" appear in the TXT file, with no linebreak. I have also tried chr(13). Any other ideas would be appreciated. Sounds to me like you might be using single quotes, i.e. '\n' rather than "\n" . If you wanted to continue with a single quotes bias (as you should!), two options: file_put_contents('/path/to/file.txt', 'Hello friend! This will appear

How to detect file ends in newline?

眉间皱痕 提交于 2019-11-29 03:19:33
Over at Can you modify text files when committing to subversion? Grant suggested that I block commits instead. However I don't know how to check a file ends with a newline. How can you detect that the file ends with a newline? grom @Konrad : tail does not return an empty line. I made a file that has some text that doesn't end in newline and a file that does. Here is the output from tail: $ cat test_no_newline.txt this file doesn't end in newline$ $ cat test_with_newline.txt this file ends in newline $ Though I found that tail has get last byte option. So I modified your script to: #!/bin/sh c=

Export a C# DataSet to a text file

一曲冷凌霜 提交于 2019-11-29 01:23:02
There are a lot of examples online of how to fill a DataSet from a text file but I want to do the reverse. The only thing I've been able to find is this but it seems... incomplete? I want it to be in a readable format, not just comma delimited, so non-equal spacing between columns on each row if that makes sense. Here is an example of what I mean: Column1 Column2 Column3 Some info Some more info Even more info Some stuff here Some more stuff Even more stuff Bits and bobs Note: I only have one DataTable within my DataSet so no need to worry about multiple DataTables. EDIT: When I said "readable

remove empty lines from text file with PowerShell

核能气质少年 提交于 2019-11-29 01:11:59
I know that I can use: gc c:\FileWithEmptyLines.txt | where {$_ -ne ""} > c:\FileWithNoEmptyLines.txt to remove empty lines. But How I can remove them with '-replace' ? 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 :) This piece of code from Randy Skretka is working fine for me, but I had the problem,