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
150
votes
12 answers

Using scanf() in C++ programs is faster than using cin?

I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention: Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee…
zeroDivisible
  • 4,041
  • 8
  • 40
  • 62
144
votes
9 answers

Is non-blocking I/O really faster than multi-threaded blocking I/O? How?

I searched the web on some technical details about blocking I/O and non blocking I/O and I found several people stating that non-blocking I/O would be faster than blocking I/O. For example in this document. If I use blocking I/O, then of course the…
yankee
  • 38,872
  • 15
  • 103
  • 162
139
votes
14 answers

How can I use a file in a command and redirect output to the same file without truncating it?

Basically I want to take as input text from a file, remove a line from that file, and send the output back to the same file. Something along these lines if that makes it any clearer. grep -v 'seg[0-9]\{1,\}\.[0-9]\{1\}' file_name >…
mike
  • 3,339
  • 6
  • 30
  • 34
136
votes
33 answers

How to add a Timeout to Console.ReadLine()?

I have a console app in which I want to give the user x seconds to respond to the prompt. If no input is made after a certain period of time, program logic should continue. We assume a timeout means empty response. What is the most straightforward…
Larsenal
  • 49,878
  • 43
  • 152
  • 220
136
votes
5 answers

console.writeline and System.out.println

What exactly is the technical difference between console.writeline and System.out.println? I know that System.out.println writes to standard output but is this not the same thing as the console? I do not fully understand the documentation for…
ziggy
  • 15,677
  • 67
  • 194
  • 287
134
votes
6 answers

How to write to a CSV line by line?

I have data which is being accessed via http request and is sent back by the server in a comma separated format, I have the following code : site= 'www.example.com' hdr = {'User-Agent': 'Mozilla/5.0'} req = urllib2.Request(site,headers=hdr) page =…
Mustard Tiger
  • 3,520
  • 8
  • 43
  • 68
133
votes
6 answers

Reading a file using a relative path in a Python project

Say I have a Python project that is structured as follows: project /data test.csv /package __init__.py module.py main.py __init__.py: from .module import test module.py: import csv with open("..data/test.csv")…
pbreach
  • 16,049
  • 27
  • 82
  • 120
133
votes
6 answers

Java: Difference between PrintStream and PrintWriter

What is the difference between PrintStream and PrintWriter? They have many methods in common due to which I often mix these two classes up. Moreover, I think we can use them for exactly the same things. But there has to be a difference, otherwise,…
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
132
votes
2 answers

Difference between `open` and `io.BytesIO` in binary streams

I'm learning about working with streams in Python and I noticed that the IO docs say the following: The easiest way to create a binary stream is with open() with 'b' in the mode string: f = open("myfile.jpg", "rb") In-memory binary streams are also…
Luke Whyte
  • 1,407
  • 2
  • 11
  • 10
129
votes
3 answers

Using FileSystemWatcher to monitor a directory

I am using a Windows Forms Application to monitor a directory and move the files dropped in it to another directory. At the moment it will copy the file to another directory, but when another file is added it will just end with no error message.…
deepseapanda
  • 3,717
  • 8
  • 32
  • 39
128
votes
11 answers

Editing specific line in text file in Python

Let's say I have a text file containing: Dan Warrior 500 1 0 Is there a way I can edit a specific line in that text file? Right now I have this: #!/usr/bin/env python import io myfile = open('stats.txt', 'r') dan = myfile.readline() print…
test
  • 17,706
  • 64
  • 171
  • 244
127
votes
7 answers

How to read integer value from the standard input in Java

What class can I use for reading an integer variable in Java?
Nehil Verma
  • 1,487
  • 3
  • 11
  • 5
126
votes
7 answers

What Process is using all of my disk IO

If I use "top" I can see what CPU is busy and what process is using all of my CPU. If I use "iostat -x" I can see what drive is busy. But how do I see what process is using all of the drive's throughput?
Party King
126
votes
5 answers

read complete file without using loop in java

Possible Duplicate: How to create a Java String from the contents of a file Whole text file to a String in Java I am trying to read the contents of a file using FileReader . But i want to read the file without reading a line by line . Is it…
Adesh singh
  • 2,083
  • 9
  • 24
  • 36
125
votes
7 answers

Why can't I call read() twice on an open file?

For an exercise I'm doing, I'm trying to read the contents of a given file twice using the read() method. Strangely, when I call it the second time, it doesn't seem to return the file content as a string? Here's the code f = f.open() # get the…
helpermethod
  • 59,493
  • 71
  • 188
  • 276