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

How to find out if a file exists in C# / .NET?

I would like to test a string containing a path to a file for existence of that file (something like the -e test in Perl or the os.path.exists() in Python) in C#.
Daren Thomas
  • 67,947
  • 40
  • 154
  • 200
217
votes
10 answers

Do I need to close() both FileReader and BufferedReader?

I'm reading a local file using a BufferedReader wrapped around a FileReader: BufferedReader reader = new BufferedReader(new FileReader(fileName)); // read the file // (error handling snipped) reader.close(); Do I need to close() the FileReader as…
Zilk
  • 8,917
  • 7
  • 36
  • 44
213
votes
32 answers

Why is access to the path denied?

I am having a problem where I am trying to delete my file but I get an exception. if (result == "Success") { if (FileUpload.HasFile) { try { File.Delete(Request.PhysicalApplicationPath +…
nick gowdy
  • 6,191
  • 25
  • 88
  • 157
206
votes
9 answers

How to create a file in Ruby

I'm trying to create a new file and things don't seem to be working as I expect them too. Here's what I've tried: File.new "out.txt" File.open "out.txt" File.new "out.txt","w" File.open "out.txt","w" According to everything I've read online all of…
Civatrix
  • 2,566
  • 4
  • 17
  • 16
185
votes
7 answers

How to find and replace text in a file

My code so far StreamReader reading = File.OpenText("test.txt"); string str; while ((str = reading.ReadLine())!=null) { if (str.Contains("some text")) { StreamWriter write = new StreamWriter("test.txt"); } } I know how…
Win Coder
  • 6,628
  • 11
  • 54
  • 81
177
votes
4 answers

What exactly is file.flush() doing?

I found this in the Python documentation for File Objects: flush() does not necessarily write the file’s data to disk. Use flush() followed by os.fsync() to ensure this behavior. So my question is: what exactly is Python's flush doing? I thought…
geek
  • 2,677
  • 4
  • 23
  • 21
176
votes
3 answers

What is the difference between Directory.EnumerateFiles vs Directory.GetFiles?

What is the difference between Directory.EnumerateFiles vs GetFiles? Obviously one returns an array and the other return Enumerable. Anything else?
DarthVader
  • 52,984
  • 76
  • 209
  • 300
176
votes
8 answers

Is it possible to create a File object from InputStream

Is there any way to create a java.io.File object from an java.io.InputStream ? My requirement is reading the File from a RAR . I am not trying to write a temporary File, I have a file inside RAR archive which I am trying to read.
androidgalaxyman
  • 1,797
  • 2
  • 11
  • 10
174
votes
1 answer

How can I use "puts" to the console without a line break in ruby on rails?

I have a method which goes through a loop -- I want it to output a "." each loop so I can see it in the console. however, it puts a linebreak at the end of each when I use puts ".". If there a way so that it just has a continuous line?
Satchel
  • 16,414
  • 23
  • 106
  • 192
172
votes
6 answers

In Clojure 1.3, How to read and write a file

I'd like to know the "recommended" way of reading and writing a file in clojure 1.3 . How to read the whole file How to read a file line by line How to write a new file How to add a line to an existing file
jolly-san
  • 2,047
  • 2
  • 14
  • 9
172
votes
18 answers

How to quickly check if folder is empty (.NET)?

I have to check, if directory on disk is empty. It means, that it does not contain any folders/files. I know, that there is a simple method. We get array of FileSystemInfo's and check if count of elements equals to zero. Something like that: public…
zhe
  • 2,358
  • 2
  • 15
  • 12
172
votes
4 answers

an htop-like tool to display disk activity in linux

I am looking for a Linux command-line tool that would report the disk IO activity. Something similar to htop would be really cool. Has someone heard of something like that?
user54579
  • 4,588
  • 4
  • 23
  • 19
169
votes
15 answers

How do you determine the size of a file in C?

How can I figure out the size of a file, in bytes? #include unsigned int fsize(char* file){ //what goes here? }
andrewrk
  • 30,272
  • 27
  • 92
  • 113
160
votes
6 answers

Write string to output stream

I have several output listeners that are implementing OutputStream. It can be either a PrintStream writing to stdout or to a File, or it can be writing to memory or any other output destination; therefore, I specified OutputStream as (an) argument…
yart
  • 7,515
  • 12
  • 37
  • 37
160
votes
7 answers

ValueError : I/O operation on closed file

import csv with open('v.csv', 'w') as csvfile: cwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL) for w, c in p.items(): cwriter.writerow(w + c) Here, p is a dictionary, w and c both are…
GobSmack
  • 2,171
  • 4
  • 22
  • 28