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
74
votes
5 answers

Writing File to Temp Folder

I want to use StreamWriter to write a file to the temp folder. It might be a different path on each PC, so I tried using %temp%\SaveFile.txt but it didn't work. How can I save to the temp folder, using environmental variables? And for example, can I…
BlueRay101
  • 1,447
  • 2
  • 18
  • 29
73
votes
5 answers

How to purge disk I/O caches on Linux?

I need to do it for more predictable benchmarking.
taw
  • 18,110
  • 15
  • 57
  • 76
73
votes
12 answers

Design pattern for "retrying" logic that failed?

I'm writing some reconnect logic to periodically attempt to establish a connection to a remote endpoint which went down. Essentially, the code looks like this: public void establishConnection() { try { this.connection = newConnection(); …
Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
72
votes
3 answers

Binary buffer in Python

In Python you can use StringIO for a file-like buffer for character data. Memory-mapped file basically does similar thing for binary data, but it requires a file that is used as the basis. Does Python have a file object that is intended for binary…
jelovirt
  • 5,844
  • 8
  • 38
  • 49
70
votes
10 answers

How to print integer literals in binary or hex in haskell?

How to print integer literals in binary or hex in haskell? printBinary 5 => "0101" printHex 5 => "05" Which libraries/functions allow this? I came across the Numeric module and its showIntAtBase function but have been unable to use it correctly. >…
TheOne
  • 10,819
  • 20
  • 81
  • 119
70
votes
5 answers

How to chain multiple different InputStreams into one InputStream

I'm wondering if there is any ideomatic way to chain multiple InputStreams into one continual InputStream in Java (or Scala). What I need it for is to parse flat files that I load over the network from an FTP-Server. What I want to do is to take…
Magnus
  • 3,691
  • 5
  • 27
  • 35
70
votes
4 answers

Reading two text files line by line simultaneously

I have two text files in two different languages and they are aligned line by line. I.e. the first line in textfile1 corresponds to the first line in textfile2, and so on and so forth. Is there a way to read both file line-by-line simultaneously?…
alvas
  • 115,346
  • 109
  • 446
  • 738
69
votes
4 answers

How are the O_SYNC and O_DIRECT flags in open(2) different/alike?

The use and effects of the O_SYNC and O_DIRECT flags is very confusing and appears to vary somewhat among platforms. From the Linux man page (see an example here), O_DIRECT provides synchronous I/O, minimizes cache effects and requires you to…
user625070
69
votes
3 answers

Asynchronous IO in Scala with futures

Let's say I'm getting a (potentially big) list of images to download from some URLs. I'm using Scala, so what I would do is : import scala.actors.Futures._ // Retrieve URLs from somewhere val urls: List[String] = ... // Download image (blocking…
F.X.
  • 6,809
  • 3
  • 49
  • 71
68
votes
10 answers

Quickly read the last line of a text file?

What's the quickest and most efficient way of reading the last line of text from a [very, very large] file in Java?
Jake
  • 15,007
  • 22
  • 70
  • 86
66
votes
2 answers

Haskell: can't use "map putStrLn"?

I have a list of strings, and tried this: ls = [ "banana", "mango", "orange" ] main = do map PutStrLn list_of_strings That didn't work, and I can't understand why. ghc print-list.hs print-list.hs:3:0: Couldn't match expected type `IO t'…
Jay
  • 9,585
  • 6
  • 49
  • 72
66
votes
2 answers

Preferred way to use Java ZipOutputStream and BufferedOutputStream

In Java does it matter whether I instantiate a ZipOutputStream first, or the BufferedOutputStream first? Example: FileOutputStream dest = new FileOutputStream(file); ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(dest)); // use…
jjathman
  • 12,536
  • 8
  • 29
  • 33
65
votes
5 answers

InputStream from relative path

I have a relative file path (for example "/res/example.xls") and I would like to get an InputStream Object of that file from that path. I checked the JavaDoc and did not find a constructor or method to get such an InputStream from a path/ Anyone has…
Allan Jiang
  • 11,063
  • 27
  • 104
  • 165
65
votes
4 answers

Difference between the access modes of the `File` object (ie. w+, r+)

When using files in Ruby, what is the difference between the r+ and w+ modes? What about the a+ mode?
Just a learner
  • 26,690
  • 50
  • 155
  • 234
64
votes
8 answers

Use Cases and Examples of GoF Decorator Pattern for IO

I have read in wikipedia that Decorator pattern is used for .Net and Java IO classes. Can anybody explain how this is being used? And what is the benefit of it with a possible example? There is an example of Windows forms on wikipedia but I want to…
DarthVader
  • 52,984
  • 76
  • 209
  • 300