Questions tagged [io]

In computing, input/output, or I/O, refers to the communication between an information processing system (such as a computer), and the outside world, possibly a human, or another information processing system.

In computing, input/output, or I/O, refers to the communication between an information processing system (such as a computer), and the outside world, possibly a human, or another information processing system.

(Source: Wikipedia [Input/Output])


I/O includes tasks such as:

  • Reading and writing files ()
  • Interacting with a user through a command-line terminal session ( / / )
  • Connecting programs so that one sends its output to the next (s)
  • Sending data over a network in packets or as a data stream ()

For the Io language, see

17482 questions
419
votes
29 answers

Cannot delete directory with Directory.Delete(path, true)

I'm using .NET 3.5, trying to recursively delete a directory using: Directory.Delete(myPath, true); My understanding is that this should throw if files are in use or there is a permissions problem, but otherwise it should delete the directory and…
Jason Anderson
  • 9,003
  • 5
  • 30
  • 25
410
votes
14 answers

Unicode (UTF-8) reading and writing to files in Python

I'm having some brain failure in understanding reading and writing text to a file (Python 2.4). # The string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) ("u'Capit\xe1n'", "'Capit\xc3\xa1n'") print…
Gregg Lind
  • 20,690
  • 15
  • 67
  • 81
401
votes
12 answers

byte[] to file in Java

With Java: I have a byte[] that represents a file. How do I write this to a file (ie. C:\myfile.pdf) I know it's done with InputStream, but I can't seem to work it out.
elcool
  • 6,041
  • 7
  • 29
  • 44
374
votes
9 answers

Save and load MemoryStream to/from a file

I am serializing an structure into a MemoryStream and I want to save and load the serialized structure. So, How to Save a MemoryStream into a file and also load it back from file?
Mahdi Ghiasi
  • 14,873
  • 19
  • 71
  • 119
340
votes
19 answers

Parsing CSV files in C#, with header

Is there a default/official/recommended way to parse CSV files in C#? I don't want to roll my own parser. Also, I've seen instances of people using ODBC/OLE DB to read CSV via the Text driver, and a lot of people discourage this due to its…
David Pfeffer
  • 38,869
  • 30
  • 127
  • 202
319
votes
9 answers

What is InputStream & Output Stream? Why and when do we use them?

Someone explain to me what InputStream and OutputStream are? I am confused about the use cases for both InputStream and OutputStream. If you could also include a snippet of code to go along with your explanation, that would be great. Thanks!
Bohemian
  • 5,957
  • 11
  • 38
  • 47
296
votes
10 answers

How to prevent SIGPIPEs (or handle them properly)

I have a small server program that accepts connections on a TCP or local UNIX socket, reads a simple command and (depending on the command) sends a reply. The problem is that the client may have no interest in the answer and sometimes exits early. …
jkramer
  • 15,440
  • 5
  • 47
  • 48
290
votes
15 answers

How to redirect 'print' output to a file?

I want to redirect the print to a .txt file using Python. I have a for loop, which will print the output for each of my .bam file while I want to redirect all output to one file. So I tried to put: f = open('output.txt','w') sys.stdout = f at the…
LookIntoEast
  • 8,048
  • 18
  • 64
  • 92
287
votes
12 answers

How to write a large buffer into a binary file in C++, fast?

I'm trying to write huge amounts of data onto my SSD(solid state drive). And by huge amounts I mean 80GB. I browsed the web for solutions, but the best I came up with was this: #include const unsigned long long size =…
Dominic Hofer
  • 5,751
  • 4
  • 18
  • 23
281
votes
11 answers

Load data from txt with pandas

I am loading a txt file containig a mix of float and string data. I want to store them in an array where I can access each element. Now I am just doing import pandas as pd data = pd.read_csv('output_list.txt', header = None) print data This is…
albus_c
  • 6,292
  • 14
  • 36
  • 77
280
votes
9 answers

Difference between fprintf, printf and sprintf?

Can anyone explain in simple English about the differences between printf, fprintf, and sprintf with examples? What stream is it in? I'm really confused between the three of these while reading about "File Handling in C".
Vishwanath Dalvi
  • 35,388
  • 41
  • 123
  • 155
276
votes
11 answers

Confused by python file mode "w+"

From the doc, Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+' truncates the file). Append 'b' to the mode to open the file in binary mode, on systems that differentiate between binary and text files; on systems that don’t have…
holys
  • 13,869
  • 15
  • 45
  • 50
268
votes
12 answers

How to check for file lock?

Is there any way to check whether a file is locked without using a try/catch block? Right now, the only way I know of is to just open the file and catch any System.IO.IOException.
ricree
  • 35,626
  • 13
  • 36
  • 27
263
votes
4 answers

How to open a file using the open with statement

I'm looking at how to do file input and output in Python. I've written the following code to read a list of names (one per line) from a file into another file while checking a name against the names in the file and appending text to the occurrences…
Disnami
  • 2,903
  • 2
  • 17
  • 15
259
votes
3 answers

cout is not a member of std

I'm practicing using mulitple files and header files etc. So I have this project which takes two numbers and then adds them. Pretty simple. Here are my files: main.cpp #include #include "add.h" int main() { int x = readNumber(); …
Paul Hannon
  • 2,613
  • 2
  • 13
  • 5