Questions tagged [file-read]

This tag can be used on questions about reading files.

To work with stored data, file handling belongs to the core knowledge of every programmer. One of the core file handling methods is reading a file.

Resources:

577 questions
6
votes
2 answers

csv file read - every single character in one single list

I am rather new to python and could really need some help (I did not find anything that helped me by now). I want to read a csv-file to a list, but unfortunately my output is not as expected. Instead of having a list…
6
votes
3 answers

Concurrent read/write file in Java

I have to read a text file from my Java application. The file contains many rows and this file is updated every X minutes from an external unknown application that appends new lines to the file. I have to read all the rows from the file and then I…
Roberto Milani
  • 700
  • 2
  • 17
  • 33
6
votes
6 answers

How to remove line break when reading files in Ruby

I'm trying to get rid of the brackets [] and the new line \n from being printed. My code looks like: name1 = File.readlines('first.txt').sample(1) name2 = File.readlines('middle.txt').sample(1) name3 = File.readlines('last.txt').sample(1) name =…
marriedjane875
  • 573
  • 2
  • 7
  • 21
6
votes
3 answers

java: how to use bufferedreader to read specific line

Lets say I have a text file called: data.txt (contains 2000 lines) How do I read given specific line from: 500-1500 and then 1500-2000 and display the output of specific line? this code will read whole files (2000 line) public static String…
Redbox
  • 1,307
  • 5
  • 16
  • 21
5
votes
3 answers

Ocaml - Files and parsing

How to read contents from file in ocaml? Specifically how to parse them? Example : Suppose file contains (a,b,c);(b,c,d)| (a,b,c,d);(b,c,d,e)| then after reading this, I want two lists containing l1 = [(a,b,c);(b,c,d)] and l2 =…
priyanka
  • 945
  • 9
  • 20
5
votes
2 answers

Python 2.7 CSV file read/write \xef\xbb\xbf code

I have a question about Python 2.7 read/write csv file with 'utf-8-sig' code, my csv . header is ['\xef\xbb\xbfID;timestamp;CustomerID;Email'] there have some code("\xef\xbb\xbfID") I read from file A.csv and I want write the same code and header…
SharpLu
  • 924
  • 1
  • 9
  • 22
5
votes
4 answers

Unit test file reading method with OpenFileDialog c#

I have a function, that returns text file path and file content: public static Tuple OpenTextFile() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog .Filter = "Text |*.txt"; bool? accept =…
Alexandr Smushko
  • 317
  • 4
  • 21
5
votes
2 answers

\377 character in c

i am trying to read a file in c. i have a .txt file and it has that content: file_one.txt file_two.txt file_three.txt file_four.txt when i try to read this file with fopen i get this output: file_one.txt file_two.txt file_three.txt…
saidozcan
  • 1,763
  • 8
  • 25
  • 38
4
votes
6 answers

How to determine 'word' size in Python

I need to know the number of bytes in a 'word' in Python. The reason I need this is I have the number of words I need to read from a file; if I knew the number of bytes in a word, I can use the file.read(num_bytes) function to read the appropriate…
jlconlin
  • 11,876
  • 20
  • 62
  • 91
4
votes
2 answers

C++, weird behavior while reading binary ifstream

For my first question here, I'd like to talk about reading binary files in C++; I'm recoding an ID3 tag library. I'm parsing the header which is a binary file, the first 10bytes are as follow: ID3 = 3 bytes = constant identifier 0xXXXX = 2 bytes…
Arnaud M
  • 43
  • 3
4
votes
1 answer

python multiprocessing read file cost too much time

there is a function in my code that should read the file .each file is about 8M,however the reading speed is too low,and to improve that i use the multiprocessing.sadly,it seems it got blocked.i wanna know is there any methods to help solve this and…
lizlalala
  • 291
  • 3
  • 12
4
votes
2 answers

Why is eof() never returning true?

I'm trying to make my program read in data from a data (.dat) file (which is really just a text file). So of course I'm using the loop condition while(!file.eof()), but this is never returning true. Here's my function: void Table::readIn(const char…
Logan Kling
  • 549
  • 2
  • 4
  • 16
4
votes
1 answer

Read a file until a character in C

Say I have a file with the format: key1/value1 key2/value2 key3/value3 .... Say I have an array to hold these values: char *data[10][10] How would I read this file and get key1, key2, and key3 into data[0][0], data[1][0], and data[2][0]. Then put…
Mohit Deshpande
  • 48,747
  • 74
  • 187
  • 247
4
votes
2 answers

fread doesn't read multiple lines

I am trying to read from a .txt file that has some numbers in lines. It looks like that. example.txt 123 456 789 555 I open this as a binary file for reading wanted to read this file line by line so i know that in every line theres 4 characters (3…
Blenikos
  • 693
  • 11
  • 18
3
votes
4 answers

Read file and get key=value without using java.util.Properties

I'm building a RMI game and the client would load a file that has some keys and values which are going to be used on several different objects. It is a save game file but I can't use java.util.Properties for this (it is under the specification). I…
Samuel Guimarães
  • 554
  • 3
  • 6
  • 18
1
2
3
38 39