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
98
votes
6 answers

Listing files in a directory matching a pattern in Java

I'm looking for a way to get a list of files that match a pattern (pref regex) in a given directory. I've found a tutorial online that uses apache's commons-io package with the following code: Collection getAllFilesThatMatchFilenameExtension(String…
Omar Kooheji
  • 54,530
  • 68
  • 182
  • 238
98
votes
2 answers

Create a file from a ByteArrayOutputStream

Can someone explain how I can get a file object if I have only a ByteArrayOutputStream. How to create a file from a ByteArrayOutputStream?
Al Phaba
  • 6,545
  • 12
  • 51
  • 83
98
votes
12 answers

How to display a progress indicator in pure C/C++ (cout/printf)?

I'm writing a console program in C++ to download a large file. I know the file size, and I start a work thread to download it. I want to show a progress indicator to make it look cooler. How can I display different strings at different times, but at…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
96
votes
6 answers

Java's createNewFile() - will it also create directories?

I've got a conditional to check if a certain file exists before proceeding (./logs/error.log). If it isn't found I want to create it. However, will File tmp = new File("logs/error.log"); tmp.createNewFile(); also create logs/ if it doesn't exist?
user623990
94
votes
3 answers

Java: what exactly is the difference between NIO and NIO.2?

I don't quite understand how different they are from each other so I have some inquiries regarding these two packages. After looking around a bit on Google, it seems like Oracle decided to update the NIO package with the newer and enhanced NIO.2…
John Huynh
  • 943
  • 1
  • 7
  • 5
93
votes
6 answers

How to read from standard input line by line?

What's the Scala recipe for reading line by line from the standard input ? Something like the equivalent java code : import java.util.Scanner; public class ScannerTest { public static void main(String args[]) { Scanner sc = new…
Andrei Ciobanu
  • 12,500
  • 24
  • 85
  • 118
93
votes
5 answers

Most efficient way to create InputStream from OutputStream

This page: http://blog.ostermiller.org/convert-java-outputstream-inputstream describes how to create an InputStream from OutputStream: new ByteArrayInputStream(out.toByteArray()) Other alternatives are to use PipedStreams and new threads which is…
Vagif Verdi
  • 4,816
  • 1
  • 26
  • 31
92
votes
6 answers

What's so bad about Lazy I/O?

I've generally heard that production code should avoid using Lazy I/O. My question is, why? Is it ever OK to use Lazy I/O outside of just toying around? And what makes the alternatives (e.g. enumerators) better?
Dan Burton
  • 53,238
  • 27
  • 117
  • 198
91
votes
2 answers

Haskell "do nothing" IO, or if without else

I want to do something in Haskell that looks like this: main1 = do s <- getLine if s == "foo" then putStr "You entered foo" Obviously this isn't legal since there's no else. One alternative I've thought of: nop :: IO () nop = sequence_…
Dave B
  • 1,091
  • 2
  • 8
  • 5
91
votes
8 answers

What is StringIO in python used for in reality?

What exactly is StringIO used for? I have been looking around the internet for some examples. However, almost all of the examples are very abstract. And they just show "how" to use it. But none of them show "why" and "in which circumstances" one…
Hossein
  • 40,161
  • 57
  • 141
  • 175
90
votes
4 answers

How do I create crossplatform file paths in Go?

I want to open a given file "directory/subdirectory/file.txt" in golang. What is the recommended way to express such a path in an OS agnostic way (ie backslashes in Windows, forward slashes in Mac and Linux)? Something like Python's os.path module?
Jjed
  • 1,296
  • 1
  • 8
  • 12
90
votes
4 answers

Get a TextReader from a Stream?

I'm trying to read an embedded text file with System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resource); but it gives me a Stream. The embedded resource is a text file so, how can I turn this Stream into a TextReader?
Juan
  • 15,274
  • 23
  • 105
  • 187
89
votes
12 answers

File exists and IS directory, but listFiles() returns null

The documentation for File.listFiles() suggests that null will ONLY be returned in the case that the file calling it is not a directory. I have the following: String dir = "/storage/emulated/0"; File f = new…
Wilson
  • 8,570
  • 20
  • 66
  • 101
88
votes
13 answers

Why are bitwise shifts (<< and >>) used for cout and cin?

Question is in the title really; I'm sure there is something logical, but for now I'm stumped!
Crowstar
  • 891
  • 1
  • 6
  • 6
88
votes
9 answers

How to copy file from one location to another location?

I want to copy a file from one location to another location in Java. What is the best way to do this? Here is what I have so far: import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; import java.util.List; public class…
vijayk
  • 2,633
  • 14
  • 38
  • 59