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
88
votes
3 answers

Force "git status" to output color on the terminal (inside a script)

EDIT: I would like to make a recommendation that parsing colors is a generally ill-conceived idea. Part of why i wanted it was so I can both parse it and pass it along in my own script output. This is... okay, but it would probably be saner to use…
Steven Lu
  • 41,389
  • 58
  • 210
  • 364
88
votes
1 answer

Linux: When to use scatter/gather IO (readv, writev) vs a large buffer with fread

In scatter and gather (i.e. readv and writev), Linux reads into multiple buffers and writes from multiple buffers. If say, I have a vector of 3 buffers, I can use readv, OR I can use a single buffer, which is of combined size of 3 buffers and do…
Jimm
  • 8,165
  • 16
  • 69
  • 118
87
votes
13 answers

How do I copy and paste data into R from the clipboard?

I have my data open in another application (e.g. a spreadsheet, like Excel, or a text editor). If I copy that data to my operating system clipboard, how can I read it into R as a data.frame?
Moderat
  • 1,462
  • 4
  • 17
  • 21
85
votes
6 answers

Fast textfile reading in c++

I am currently writing a program in c++ which includes reading lots of large text files. Each has ~400.000 lines with in extreme cases 4000 or more characters per line. Just for testing, I read one of the files using ifstream and the implementation…
Arne
  • 17,706
  • 5
  • 83
  • 99
85
votes
9 answers

Wait Until File Is Completely Written

When a file is created (FileSystemWatcher_Created) in one directory I copy it to another. But When I create a big (>10MB) file it fails to copy the file, because it starts copying already, when the file is not yet finished creating... This causes…
levi
  • 3,451
  • 6
  • 50
  • 86
84
votes
8 answers

How to read a file as a byte array in Scala

I can find tons of examples but they seem to either rely mostly on Java libraries or just read characters/lines/etc. I just want to read in some file and get a byte array with scala libraries - can someone help me with that?
fgysin
  • 11,329
  • 13
  • 61
  • 94
84
votes
9 answers

How can I print 0x0a instead of 0xa using cout?

How can I print 0x0a, instead of 0xa using cout? #include using std::cout; using std::endl; using std::hex; int main() { cout << hex << showbase << 10 << endl; }
Ayrosa
  • 3,385
  • 1
  • 18
  • 29
84
votes
8 answers

What is the motivation for Scala assignment evaluating to Unit rather than the value assigned?

What is the motivation for Scala assignment evaluating to Unit rather than the value assigned? A common pattern in I/O programming is to do things like this: while ((bytesRead = in.read(buffer)) != -1) { ... But this is not possible in Scala…
Graham Lea
  • 5,797
  • 3
  • 40
  • 55
84
votes
2 answers

The best way to get a string from a Writer

I have a piece of code that returns a web page using the built-in template system. It accepts a ResponseWriter to which the resulting markup is written. I now want to get to the markup as a string and put it in a database in some cases. I factored…
froderik
  • 4,642
  • 3
  • 33
  • 43
82
votes
4 answers

How to use Bash read with a timeout?

I can ask the user to press Enter by using read, and have him wait by calling sleep. But I can’t think of a way of doing both at the same time. I would like the user to be given the choice: Press Ctrl+C to Cancel, Enter to continue or just wait…
qdii
  • 12,505
  • 10
  • 59
  • 116
80
votes
7 answers

Getting "java.nio.file.AccessDeniedException" when trying to write to a folder

For some reason I keep getting java.nio.file.AccessDeniedException every time I try to write to a folder on my computer using a java webapp on Tomcat. This folder has permissions set to full control for everyone on my computer (Windows). Does…
OneTwo
  • 2,291
  • 6
  • 33
  • 55
80
votes
2 answers

Why is the CPU not needed to service I/O requests?

I am learning about operating systems but there is a small concept I cannot grasp. Say a process 1 is running on the CPU and then it issues an I/O request to read from a disk. For efficiency, the CPU begins executing process 2 as this request is…
Pat Murray
  • 4,125
  • 7
  • 28
  • 33
78
votes
6 answers

How to output a character as an integer through cout?

#include using namespace std; int main() { char c1 = 0xab; signed char c2 = 0xcd; unsigned char c3 = 0xef; cout << hex; cout << c1 << endl; cout << c2 << endl; cout << c3 << endl; } I expected…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
77
votes
4 answers

How to use gdb with input redirection?

In the Terminal, I have: myapp < myfileinput But if I want to use gdb, gdb myapp < myfileinput It didn't run correctly. How to use gdb here?
user53670
75
votes
3 answers

What's a reasonable way to read an entire text file as a single string?

I am sure this is an easy one; I just couldn't find the answer immediately from Google. I know I could do this (right?): text = "" File.open(path).each_line do |line| text += line end # Do something with text But that seems a bit excessive,…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447