file-io

Splitting text file into 2D array

我们两清 提交于 2021-01-29 05:20:56
问题 this is the text file that i want to split into a 2D array "YHOO",36.86,21,13873900,37.00 "GOOG",684.11,1114,1821650,686.72 "MSFT",50.54,3993,31910300,50.65 "AAPL",94.40,28201,39817000,94.26 and this is the code I have implemented to do this but it won't work String input = File.ReadAllText(@"..\..\Data\stockInfo.txt"); int i = 0, j = 0; string[,] result = new string[3, 5]; foreach (var row in input.Split('\n')) { j = 0; foreach (var col in row.Trim().Split(',')) { result[i, j] = string.Parse

Read embedded text file as string array (C#)

对着背影说爱祢 提交于 2021-01-29 02:54:40
问题 I'm trying to read an embedded textfile. The text file has the structure: Word1 Word2 Word3 ... I'm trying to get this into a string array, but am unable to do so. I mean, i've come across this: How to read embedded resource text file but this only reads the file as a string and while i could read the string, then separate it out line-by-line, there seems like there should be a simpler solution. Is there? 回答1: I use this extension method for splitting lines: public static string[] GetLines

How to programmatically close select file dialog

拥有回忆 提交于 2021-01-29 01:48:13
问题 I have a input field with the type=file to select an image file but what I want is that if someone opens the file selector dialog and on some particular event it automatically / programmatically closes the dialog without hitting the cancel button by the user. Is there any way to do it with js/jquery? 回答1: Interaction with <input type="file" /> is very limited. There is no way to close the file dialog programmatically. You could potentially try to disable the drag/drop functionality while the

How to programmatically close select file dialog

久未见 提交于 2021-01-29 01:40:57
问题 I have a input field with the type=file to select an image file but what I want is that if someone opens the file selector dialog and on some particular event it automatically / programmatically closes the dialog without hitting the cancel button by the user. Is there any way to do it with js/jquery? 回答1: Interaction with <input type="file" /> is very limited. There is no way to close the file dialog programmatically. You could potentially try to disable the drag/drop functionality while the

Octave dlmread won't read date format

白昼怎懂夜的黑 提交于 2021-01-28 20:10:03
问题 I have a csv file, the one from https://www.kaggle.com/jolasa/waves-measuring-buoys-data-mooloolaba/downloads/waves-measuring-buoys-data-mooloolaba.zip/1. The first entries look like this: The first column has dates which I'm trying to read with this command: matrix = dlmread ('waves-measuring-buoys-data/WavesMooloolabaJan2017toJun2019.csv',',',1,0); (If referring to file on Kaggle, note that I slightly modified the directory and file names for ease of reading) Then when I check a date by

Compute entropy of different file extensions to find randomness of data?

北城余情 提交于 2021-01-28 07:12:41
问题 I have different file types which includes JPEG and jpg ,#mp3 ,#GIF,#MP4,#FLV, M4V ,exe, zip etc. Take data in blocks , something like 4k block size, find randomness Generate randomness score between 0 and 1 Try to put classes according to the randomness score. How can we find entropy of different types of files as mentioned above and can we scale each of the file score between 0 and 1. 回答1: +1 very interesting question here few untested ideas just from top of my head right now: how about

Maven hangs when taking input from Scanner

吃可爱长大的小学妹 提交于 2021-01-28 07:08:26
问题 I am designing a program that has to run with the mvn test command and take a user input from the command line. When I run the program with mvn test everything works until Scanner.next() is executed, then the CLI hangs and I have to close the program. my test method public class AppTest { @Test public void shouldAnswerWithTrue() { Scanner sc = new Scanner(System.in); System.out.println("Awaiting input"); String in = sc.next(); System.out.println("TEST!" + in); assertTrue( true ); } } my pom

Storing numerical value from a binary file into an array- C++

余生颓废 提交于 2021-01-28 06:13:02
问题 I am trying to read numerical data from a binary file containing 100 double values and store it in an array called myArray. When I print myArray nothing is being shown, as if myArray has never been filled. Any help is appreciated. int main() { int file_len; ifstream infile; infile.open("mybinfile.bin", ios::binary | ios::in); if (!infile.is_open()) { cout << "Error in opening the file. " << endl; } else { const int file_len = 100; std::vector<char> myVect; myVect.resize(file_len); int i = 0;

Writing data to a text file

我的未来我决定 提交于 2021-01-28 01:40:21
问题 I have a simple program where I write 6 of 7 numbers to a text file. Logically everything seems to be fine. However the numbers are not written to the file as expected. Random random = new Random(); Console.WriteLine("Please enter the name of the numbers file"); string fileLotto = Console.ReadLine(); //creating the lotto file FileStream fs = new FileStream("../../" + fileLotto + ".txt", FileMode.OpenOrCreate, FileAccess.Write); BufferedStream bs = new BufferedStream(fs); Console.WriteLine(

Reading multiple text files in C

一世执手 提交于 2021-01-27 21:30:21
问题 What is the correct way to read and extract data from text files when you know that there will be many in a directory? I know that you can use fopen() to get the pointer to the file, and then do something like while(fgets(..) != null){} to read from the entire file, but then how could I read from another file? I want to loop through every file in the directory. 回答1: Sam, you can use opendir/readdir as in the following little function. #include <stdio.h> #include <dirent.h> static void scan